-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.ahk
435 lines (335 loc) · 8.61 KB
/
helper.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Set up our pen constants
global SPEN_NOT_HOVERING := 0x0 ; Pen is moved away from screen.
global SPEN_HOVERING := 0x0 ; Pen is hovering above screen.
global SPEN_TOUCHING := 0x1 ; Pen is touching screen.
global SPEN_BTN_HOVERING := 0x8
global SPEN_BTN_TOUCHING := 0xC
; Respond to the pen inputs
; Fill this section with your favorite AutoHotkey scripts!
; lastInput is the last input that was detected before a state change.
PenCallback(input, lastInput) {
if(lastInput = SPEN_HOVERING and input = SPEN_BTN_HOVERING)
{
; assume it is "down"
; MsgBox, Pressed
Send, {F13}
}
if(lastInput = SPEN_BTN_HOVERING and input = SPEN_HOVERING)
{
; assume it is "up"
Send, {F14}
}
if(lastInput = SPEN_BTN_HOVERING and input = SPEN_BTN_TOUCHING)
{
; assume btn_touching
Send, {F15}
}
}
global raw_pen_x
global raw_pen_y
; Include AHKHID
#include AHKHID.ahk
; Set up other constants
; USAGE_PAGE and USAGE might change on different devices...
WM_INPUT := 0xFF
USAGE_PAGE := 13
USAGE := 2
; Set up AHKHID constants
AHKHID_UseConstants()
; Register the pen
AHKHID_AddRegister(1)
AHKHID_AddRegister(USAGE_PAGE, USAGE, A_ScriptHwnd, RIDEV_INPUTSINK)
AHKHID_Register()
; Intercept WM_INPUT
OnMessage(WM_INPUT, "InputMsg")
; Callback for WM_INPUT
; Isolates the bits responsible for the pen states from the raw data.
InputMsg(wParam, lParam) {
Local type, inputInfo, inputData, raw, proc
Critical
type := AHKHID_GetInputInfo(lParam, II_DEVTYPE)
if (type = RIM_TYPEHID) {
inputInfo := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
inputData := AHKHID_GetInputData(lParam, uData)
raw := NumGet(uData, 0, "UInt")
proc := (raw >> 8) & 0x1F
raw_pen_x := NumGet(uData, 2, "UShort")
raw_pen_y := NumGet(uData, 4, "UShort")
LimitPenCallback(proc)
}
}
; Limits the callback only to when the pen changes state.
; This stop the repetitive firing that goes on when the pen moves around.
LimitPenCallback(input) {
static lastInput := PEN_NOT_HOVERING
if (input != lastInput) {
PenCallback(input, lastInput)
lastInput := input
}
}
; following is done by d0ot[at]github
; any questions, feel free to contact me!
; Configurations start
; get it by Windows Spy
global lasso_offset_x := 227
global lasso_offset_y := 125
global earser_offset_x := 357
global earser_offset_y := 125
global pen1_offset_x := 420
global pen1_offset_y := 125
global pen2_offset_x := 490
global pen2_offset_y := 125
global win_title_regex := ".*OneNote"
global program_executable := "OneNoteUWP"
global click_max_interval := 300
global quick_panel_wait := 300
; Configurations end
; Wacom Feel It Constant for GB12
global PEN_X_MAX := 25272
global PEN_Y_MAX := 16848
; for tool switch
global TOOL_NULL := 0
global TOOL_PEN := 1
global TOOL_LASSO := 2
global TOOL_EARSER := 3
global tool_in_use := TOOL_PEN
; for button_timer
global btn_timer_on := 0
global btn_up_count := 0
global btn_down_count := 0
global btn_last_down_count := 0
global btn_last_up_count := 0
global btn_touching := 0
global win_title := "Default"
global gui1Hwnd := 0
global quick_panel_width := 100
Gui, New, +AlwaysOnTop -Caption +Hwndgui1Hwnd
; debug code
; MsgBox, %gui1Hwnd%
Gui, %gui1Hwnd%:Add, Text,, Quick Panel
Gui, %gui1Hwnd%:Add, Button, Default w%quick_panel_width%, Cancel
Gui, %gui1Hwnd%:Add, Button, Default w%quick_panel_width%, Copy
Gui, %gui1Hwnd%:Add, Button, Default w%quick_panel_width%, Paste
Gui, %gui1Hwnd%:Add, Button, Default w%quick_panel_width%, Delete
ButtonCancel:
Gui, %gui1Hwnd%:Hide
return
ButtonCopy:
Gui, %gui1Hwnd%:Hide
Sleep, %quick_panel_wait%
Send, ^c
return
ButtonPaste:
Gui, %gui1Hwnd%:Hide
Sleep, %quick_panel_wait%
Send, ^v
return
ButtonDelete:
Gui, %gui1Hwnd%:Hide
Sleep, %quick_panel_wait%
Send, {Delete Down}{Delete Up}
return
global pen_pos_x_cache
global pen_pos_y_cache
pen_pos_update()
{
SysGet, pm, MonitorPrimary
SysGet, Mon2, Monitor, %pm%
pm_width := Mon2Right - Mon2Left
pm_height := Mon2Bottom - Mon2Top
if(pm_width > pm_height)
{
pen_pos_x_cache := (raw_pen_x / PEN_X_MAX) * pm_width
pen_pos_y_cache := (raw_pen_y / PEN_Y_MAX) * pm_height
}else
{
pen_pos_y_cache := pm_width - (raw_pen_x / PEN_X_MAX) * pm_width
pen_pos_x_cache := (raw_pen_y / PEN_Y_MAX) * pm_height
}
}
get_pen_pos_x()
{
pen_pos_update()
return pen_pos_x_cache
}
get_pen_pos_y()
{
pen_pos_update()
return pen_pos_y_cache
}
show_quick_panel()
{
CoordMode, Mouse, Screen
qp_x := get_pen_pos_x() - (quick_panel_width / 2)
qp_y := get_pen_pos_y() - 50
Gui, %gui1Hwnd%:Show, X%qp_x% Y%qp_y%
}
apply_click(winTitleRegEx, offset_x, offset_y)
{
winTitle := 0
SetTitleMatchMode, RegEx
WinGetTitle, winTitle, %winTitleRegEx%
WinGetPos, x, y, w, h, %winTitle%
click_x := x + offset_x
click_y := y + offset_y
CoordMode, Mouse, Screen
click, %click_x%, %click_y%
}
get_win_title_regex(winTitleRegEx)
{
winTitle := 0
SetTitleMatchMode, RegEx
WinGetTitle, winTitle, %winTitleRegEx%
return winTitle
}
; skip the regex match process
apply_click_quick(winTitle, offset_x, offset_y)
{
WinGetPos, x, y, w, h, %winTitle%
click_x := x + offset_x
click_y := y + offset_y
CoordMode, Mouse, Screen
click, %click_x%, %click_y%
}
select_draw(offset_x, offset_y)
{
Send, {Alt Down}d{Alt Up}
Sleep, 100
apply_click(win_title_regex, offset_x, offset_y)
}
button_timer()
{
; if touching down, all previous btn input is assumed to be invalid
;MsgBox, Time get
if(btn_touching = 1)
{
SetTimer, button_timer, Off
btn_timer_on := 0
return
}
if(btn_down_count = btn_last_down_count)
{
SetTimer, button_timer, Off
btn_timer_on := 0
; btn_down_count times press and release
if(btn_up_count = btn_down_count)
{
; debug code
; MsgBox, %btn_down_count% times, not long;
actions(btn_down_count, 0)
}
else
{
; btn_down_count times press and
; btn_up_count times release
; long press detected
; debug code
; MsgBox, %btn_down_count% times, long;
actions(btn_down_count, 1)
}
}else
{
btn_last_down_count := btn_down_count
btn_last_up_count := btn_up_count
}
}
; single click for pen
; double click for lasso
; for pen btn down
F13::
;MsgBox, F9 get btn_timer_on = %btn_timer_on%
if (btn_timer_on = 0)
{
btn_down_count := 1
btn_down_last_count := 1
btn_up_count := 0
btn_last_up_count := 0
btn_touching := 0
btn_timer_on := 1
SetTimer, button_timer, %click_max_interval%
}
else
{
btn_down_count := btn_down_count + 1
}
return
; for pen btn up
F14::
if (btn_timer_on = 1)
{
btn_up_count := btn_up_count + 1
}
return
F15::
btn_touching := 1
return
; times of press
; long is 1 for long press
actions(times, long)
{
if(long = 0)
{
; debug code
; MsgBox, times = %times%
if(times = 1)
{
ret := get_win_title_regex(win_title_regex)
if(StrLen(ret) = 0)
{
launch_program()
}else
{
if(Winactive(win_title_regex))
{
switch_tool()
} else
{
WinActivate, %win_title_regex%
}
}
}
if(times = 2)
{
; copy, paste, delete
show_quick_panel()
}
if(times = 3)
{
}
}else
{
if(times = 1)
{
px := get_pen_pos_x()
py := get_pen_pos_y()
CoordMode, Mouse, Screen
Click, right, %px%, %py%
}
if(times = 2)
{
Send, #+s
}
}
}
launch_program()
{
Run, %program_executable%
}
; switch pen and lasso
switch_tool()
{
if(tool_in_use = TOOL_PEN)
{
apply_click(win_title_regex, lasso_offset_x, lasso_offset_y)
tool_in_use := TOOL_LASSO
}
else
{
apply_click(win_title_regex, pen2_offset_x, pen2_offset_y)
tool_in_use := TOOL_PEN
}
}