This repository has been archived by the owner on May 26, 2022. It is now read-only.
forked from jonathanyip/Surface-Pro-3-AutoHotkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPen.ahk
210 lines (162 loc) · 5.5 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
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
; StylusButtonGesture-AutoHotkey
;https://github.com/PBW99/StylusButtonGesture-AutoHotkey
;
;Forked From Surface Pro 3 AutoHotkey
; https://github.com/jonathanyip/Surface-Pro-3-AutoHotkey
; 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.
global RPressed := false
global MPressed := false
global G_PEN_COORD_WIDTH = 4034.0
global G_PEN_COORD_HEIGHT = 2754.0
global G_X_Ratio = A_ScreenWidth / G_PEN_COORD_WIDTH
global G_Y_Ratio = A_ScreenHeight / G_PEN_COORD_HEIGHT
global g_penX
global g_penY
global g_oldX
global g_oldY
global g_PressNum := 0
; Create the array, initially empty:
global g_Array := []
; Input Check
global g_llastInput
CvtPenCrd_To_MouseCrd(ByRef mouseX, ByRef mouseY){
mouseX := g_penX * G_X_Ratio
mouseY := g_penY * G_Y_Ratio
}
; 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) {
OutputDebug, input---%input%, last %lastInput%
if (input = PEN_NOT_HOVERING) {
if(RPressed){
mouX :=0
mouY :=0
CvtPenCrd_To_MouseCrd(mouX,mouY)
OutputDebug, newmouse---%mouX%, %mouY%
MouseClick, right,mouX,mouY, 1, 0, U ;
g_PressNum:=0
RPressed := false
}
}
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_TOUCHING) {
if(RPressed){
MouseClick, right,g_oldX,g_oldY, 1, 0, U ;
}
g_PressNum:=0
RPressed := false
g_Array := []
return
}
if (input = PEN_2ND_BTN_HOVERING AND g_llastInput != PEN_2ND_BTN_TOUCHING) {
mouX :=0
mouY :=0
CvtPenCrd_To_MouseCrd(mouX,mouY)
if (RPressed = false){
RPressed := true
g_oldX := mouX
g_oldY := mouY
MouseClick, right,g_oldX,g_oldY, 1, 0, D ;
OutputDebug, oldmouse---%g_oldX%, %g_oldY%
}else{
newPos := {}
newPos.x := mouX
newPos.y := mouY
MouseMove, mouX,mouY,0
OutputDebug, mid---%x%, %y%
g_Array.Push(newPos)
}
}else {
if(RPressed = true){
mouX :=0
mouY :=0
CvtPenCrd_To_MouseCrd(mouX,mouY)
OutputDebug, newmouse---%mouX%, %mouY%
MouseClick, right,mouX,mouY, 1, 0, U ;
RPressed := false
g_Array := []
; Mulitple Click
if g_PressNum > 0 ; SetTimer already started, so we log the keypress instead.
{
g_PressNum += 1
if(g_PressNum > 1){
; 2BTN double Clicked
Send, #{Tab}
g_PressNum = 0
}
}else{
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
g_PressNum := 1
SetTimer, KeyWinC, -300 ;
}
}
}
}
; 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)
flag := AHKHID_GetInputInfo(lParam,II_MSE_FLAGS)
inputData := AHKHID_GetInputData(lParam, uData)
; Get X,Y Coord
g_penX := (NumGet(uData, 0, "UInt") & 0xffff0000) >> 16
g_penY := (NumGet(uData, 4, "UInt") & 0x0000ffff)
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
static passNum := 0
passNum+=1
if (input != lastInput) {
g_llastInput := lastInput
PenCallback(input, lastInput)
lastInput := input
}else if (Mod(passNum,10) = 0){
PenCallback(input, lastInput)
}
}
KeyWinC:
; Regardless of which action above was triggered, reset the count to
; prepare for the next series of presses:
g_PressNum := 0
return