-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathahksend.ahk
77 lines (68 loc) · 2.05 KB
/
ahksend.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
if (A_Args.Length == 0) {
help := "Usage: ahksend [-f] <key> <key>..."
help .= "`n"
help .= "`n <key> <key> is one of the following:"
help .= "`n An autohotkey key combo (like ^!a for Ctrl+Shift+a)"
help .= "`n See https://www.autohotkey.com/docs/v2/lib/Send.htm"
help .= "`n"
help .= "`n S:<ms> sleep for the specified number of milliseconds"
help .= "`n"
help .= "`n T:<text> types the specified text"
help .= "`n"
help .= "`n R:<command> runs the specified command"
help .= "`n"
help .= "`n C:<keyname>;<truekey>;<falsekey> sends truekey if"
help .= "`n keyname is held, otherwise falsekey."
help .= "`n See https://www.autohotkey.com/docs/v2/KeyList.htm"
help .= "`n for accepted keynames. To check multiple keys join"
help .= "`n them with +, e.g Control+Shift. "
help .= "`n"
help .= "`n -f Steal focus. Focused application will not receive"
help .= "`n and intercept keypresses."
help .= "`n"
MsgBox(help)
return
}
steal_focus := 0
if (A_Args[1] == "-f") {
steal_focus := 1
focusgui := Gui()
focusgui.Show("x10000 y10000")
}
processArg(arg) {
o := SubStr(arg, 1, 2)
if (o == "S:") {
Sleep(SubStr(arg, 3))
}
else if (o == "T:") {
SendText(SubStr(arg, 3))
}
else if (o == "R:") {
Run(SubStr(arg, 3))
}
else if (o == "C:") {
arr := StrSplit(SubStr(arg, 3),";", , 3)
keys := StrSplit(arr[1],"+")
state := true
for k in keys {
state &= GetKeyState(k)
}
if (state && Trim(arr[2]) != "") {
processArg(arr[2])
}
else if (!state && arr.Length == 3 && Trim(arr[3]) != "") {
processArg(arr[3])
}
}
else {
SendInput(arg)
}
}
i := 1 + steal_focus
while i < A_Args.Length + 1 {
processArg(A_Args[i])
i += 1
}
if (steal_focus == 1) {
focusgui.Destroy()
}