-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPen.ahk
96 lines (69 loc) · 2.39 KB
/
Pen.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
; Surface Pro 3 AutoHotkey
; https://github.com/jonathanyip/Surface-Pro-3-AutoHotkey
;
; Last Updated: Sept. 14, 2016
; Set up our pen constants
global PEN_NOT_HOVERING := 0x0 ; Pen is moved away from screen.
global PEN_HOVERING := 0x1 ; Pen is hovering above screen.
global PEN_TOUCHING := 0x3 ; Pen is touching screen.
global PEN_1ST_BTN_HOVERING := 0x9 ; 1st button is pressed.
global PEN_1ST_BTN_TOUCHING := 0x11 ; 1st button is pressed, pen is touching screen.
global PEN_2ND_BTN_HOVERING := 0x5 ; 2nd button is pressed.
global PEN_2ND_BTN_TOUCHING := 0x7 ; 3nd button is pressed, pen is touching screen.
; 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 (input = PEN_NOT_HOVERING) {
}
if (input = PEN_HOVERING) {
}
if (input = PEN_TOUCHING) {
}
if (input = PEN_1ST_BTN_HOVERING) {
}
if (input = PEN_1ST_BTN_TOUCHING) {
}
if (input = PEN_2ND_BTN_HOVERING) {
}
if (input = PEN_2ND_BTN_TOUCHING) {
}
}
; 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
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
}
}