-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathExample.ahk
50 lines (44 loc) · 1.14 KB
/
Example.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#Include ActiveScript.ahk
/* Preferred usage:
; Put ActiveScript.ahk in a Lib folder, then:
#Include <ActiveScript>
*/
vb := ActiveScript("VBScript")
code := '
(
MsgBox "Hello, world!"
Dim Answer
Function GetAnswer
GetAnswer = Answer
End Function
)'
vb.Exec(code) ; Execute some VBScript.
vb.Answer := 42 ; Set a previously-declared global variable.
MsgBox vb.Answer ; Get a global variable.
MsgBox vb.GetAnswer() ; Call a function.
MsgBox vb.Eval("2 + 2") ; Evaluate an expression.
; The same thing again, but with JScript:
js := ActiveScript("JScript")
code := '
(
shell = new ActiveXObject("WScript.Shell")
shell.Popup("Hello, world!")
var Answer
function GetAnswer() {
return Answer
}
)'
; These are all the same as before:
js.Exec(code)
js.Answer := 42
MsgBox js.Answer
MsgBox js.GetAnswer()
MsgBox js.Eval("2 + 2")
; Show which scripting engine is in use; probably "5.8".
ShowVersion(js)
; To use the newer IE9+ version of JScript, use the following.
js := ActiveScript("{16d51579-a30b-4c8b-a276-0ff4dc41e755}")
ShowVersion(js)
ShowVersion(scr) {
MsgBox scr.ScriptEngineMajorVersion() "." scr.ScriptEngineMinorVersion()
}