-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetxytest.ahk
121 lines (88 loc) · 3.04 KB
/
getxytest.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
#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.
Gui, +Resize
Gui, Add, StatusBar
Gui, Show
; 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
global raw_input := 0
; 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, {F9}
MsgBox, raw_input = %raw_input%
}
if(lastInput = SPEN_BTN_HOVERING and input = SPEN_HOVERING)
{
; assume it is "up"
Send, {F10}
}
if(lastInput = SPEN_BTN_HOVERING and input = SPEN_BTN_TOUCHING)
{
; assume btn_touching
Send, {F11}
}
}
; 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_input := raw
raw := NumGet(uData, 0, "UInt")
proc := (raw >> 8) & 0x1F
; correct
raw_x := NumGet(uData, 2, "UShort")
; correct
raw_y := NumGet(uData, 4, "UShort")
; correct
raw_pressure := NumGet(uData, 6, "UShort")
; correct
raw_height := NumGet(uData, 8, "UShort")
raw_k1 := NumGet(uData, 10, "Char")
raw_k2 := NumGet(uData, 11, "Char")
raw_k3 := NumGet(uData, 12, "Char")
SB_SetText(raw_x . " | " . raw_y . " | " . raw_pressure . " | " . raw_height )
;SB_SetText(raw_k1 . " | " . raw_k2 . " | " . raw_k3)
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
}
}