-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAHK-GlobalGestures.ahk
238 lines (215 loc) · 4.39 KB
/
AHK-GlobalGestures.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
; AHK-GlobalGestures v1.25 - https://github.com/CheeseFrog/AHK-GlobalGestures
#NoEnv
#SingleInstance Force
IfExist, %A_ScriptDir%\GG1.ico
Menu, Tray, Icon, %A_ScriptDir%\GG1.ico, 1
CoordMode, Mouse, Screen
DllCall("SystemParametersInfo", UInt, 0x005E, UInt, 0, UIntP, noTrail, UInt, 0) ; get default trail
wOS:=DllCall("GetVersion")&0xFF ; Win Version
Progress, B X50 Y60 ZH0 CW121212 FM20 CTwhite,, % " ", OSD, Segoe UI Light ; OSD setup
WinSet, Transparent, 0, OSD
WinSet, ExStyle, +0x20, OSD
trail(n) { ; trail as gesture line
DllCall("SystemParametersInfo", UInt, 0x005D, UInt, n, Str, 0, UInt, 0)
}
OSD(msg) { ; On-Screen Display
Global
SetTimer, OffSD, Delete
If (msg!=old)
Progress,,, %msg%, OSD
old:=msg
WinSet, Transparent, % a:=240, OSD
SetTimer, OffSD, 1100
Return
OffSD:
WinSet, Transparent, % a:=(a>2)*a*.7, OSD
If (a)
SetTimer, OffSD, 17
Return
}
RLUD(x1, y1, x2, y2) { ; gesture logic
DZ:=33 ; deadzone
If (Abs(x2-x1)>Abs(y2-y1)) {
If ((x2-x1)>DZ)
Return 1
If ((x2-x1)<-DZ)
Return 2
}
If ((y2-y1)<-DZ)
Return 3
If ((y2-y1)>DZ)
Return 4
}
noR() { ; prevent context menu
Global
RL:=0
trail(noTrail)
If (noRclick) {
noRclick:=0
Return 1
}
}
browser() { ; gestures in chromium, firefox, IE
Global
MouseGetPos, x2, y2
If !(WinActive("ahk_class Chrome_WidgetWin_1") or WinActive("ahk_class MozillaWindowClass") or WinActive("ahk_class IEFrame"))
Return -1
If ((Abs(x2-x1)>A_ScreenWidth*.55) or (Abs(y2-y1)>A_ScreenHeight*.55)) ; long-drag gestures
Switch RLUD(x1, y1, x2, y2) {
Case 1:
Send ^{PgDn}
OSD("Tab Right")
Case 2:
Send ^{PgUp}
OSD("Tab Left")
Case 3:
Send ^{Home}
OSD("Scroll Home")
Case 4:
Send ^{End}
OSD("Scroll End")
Default:
Return -1
}
Else
Switch RLUD(x1, y1, x2, y2) {
Case 1:
Send {Browser_Forward}
OSD("Page Forward")
Case 2:
Send {Browser_Back}
OSD("Page Back")
Case 3:
Send {PgUp}
OSD("Scroll Up")
Case 4:
Send {PgDn}
OSD("Scroll Down")
Default:
Return -1
}
}
RandM(x1, y1) {
Global
While (GetKeyState("RButton", "P"))
If (GetKeyState("MButton", "P") and noRclick) {
Send {Ctrl down}{0}{Ctrl up}
OSD("Zoom Reset")
KeyWait, MButton, U
}
KeyWait, MButton, U
If (noR())
Exit
MouseGetPos, x2, y2
Switch RLUD(x1, y1, x2, y2) {
Case 1:
Send {Media_Next}
OSD("Media Next")
Case 2:
Send {Media_Prev}
OSD("Media Last")
Case 3:
Send {Media_Stop}
OSD("Media Stop")
Case 4:
Send {Media_Play_Pause}
OSD("Media Play/Pause")
Default:
Send {Ctrl down}{0}{Ctrl up}
OSD("Zoom Reset")
}
}
wheel(D) {
Global
If (GetKeyState("LButton", "P")) {
If (RL) {
noRclick:=1
If (D)
Send {Volume_Down} ; volume down
Else
Send {Volume_Up} ; volume up
If (wOS<8)
OSD("Volume "+(D?Chr(0x2212):"+"))
}
Exit
}
noRclick:=1
OSD("Zoom "+(D?Chr(0x2212):"+"))
If (D)
Send {Ctrl down}{WheelDown} ; zoom out
Else
Send {Ctrl down}{WheelUp} ; zoom in
sleep 5
Send {Ctrl up}
}
RandL(x1, y1, t1) { ; Global rocker gestures
Global
While (GetKeyState("RButton", "P"))
While (GetKeyState("LButton", "P"))
If (GetKeyState("MButton", "P")) {
noRclick:=1
Send {Volume_Mute} ; volume mute
If (wOS<8)
OSD("Volume Mute")
KeyWait, MButton, U
}
If (noR())
Exit
MouseGetPos, x2, y2
Switch RLUD(x1, y1, x2, y2) {
Case 1:
Send {Ctrl down}#{Right}{Ctrl up}
OSD("Desktop Right")
Case 2:
Send {Ctrl down}#{Left}{Ctrl up}
OSD("Desktop Left")
Case 3:
If (wOS<10)
Send {Ctrl down}#{tab}{Ctrl up}
Else
Send #{tab}
OSD("Task View")
Case 4:
Send #d
OSD("Show Desktop")
Default:
t2:=A_TickCount
If ((t2-t1) < 500)
Send {Alt down}{tab}{Alt up} ; alt-tab
Else
Send {Ctrl down}{Alt down}{tab}{Alt up}{Ctrl up} ; alt-tab menu
}
}
checkclick() {
Global
MouseGetPos, x1, y1
If !(GetKeyState("LButton", "P") or GetKeyState("MButton", "P")) ; anti-reverse rocker
While (GetKeyState("RButton", "P"))
If (GetKeyState("MButton", "P")) {
RandM(x1, y1)
Return 1
}
Else
If (GetKeyState("LButton", "P")) {
RandL(x1, y1, t1)
Return 1
}
}
RButton::
t1:=A_TickCount
trail(16) ; trail length (max 16)
If (checkclick() or noR() or !browser())
Exit
If (abs(x2-x1)+abs(y2-y1)<22) ; ignore mini-drag
Click Right
Else {
MouseMove, %x1%, %y1%, 0 ; preserve default right-click drag
Click, down, right
MouseMove, %x2%, %y2%, 2
Click, up, right
}
Return
~Rbutton & MButton::Return ; prevent M-click
~RButton & LButton::RL:=1
~Rbutton & WheelUp::wheel(0)
~Rbutton & WheelDown::wheel(1)