Repository navigation
Expand file tree
/
Copy pathkeylib.py
More file actions
163 lines (130 loc) · 3.16 KB
/
Copy pathkeylib.py
File metadata and controls
163 lines (130 loc) · 3.16 KB
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
# http://www.flint.jp/misc/?q=dik&lang=en
import ctypes
import time
SendInput = ctypes.windll.user32.SendInput
Q= 0x10
W= 0x11
E= 0x12
R= 0x13
T= 0x14
Y= 0x15
U= 0x16
I= 0x17
O= 0x18
P= 0x19
A= 0x1E
S= 0x1F
D= 0x20
F= 0x21
G= 0x22
H= 0x23
J= 0x24
K= 0x25
L= 0x26
Z= 0x2C
X= 0x2D
C= 0x2E
V= 0x2F
B= 0x30
N= 0x31
M= 0x32
CTRL = 0x1D
SHIFT = 0x2A
SPACE = 0x39
ENTER = 0x1c
string_to_hex_match = {
"A": A,
"B": B,
"C": C,
"D": D,
"E": E,
"F": F,
"G": G,
"H": H,
"I": I,
"J": J,
"K": K,
"L": L,
"M": M,
"N": N,
"O": O,
"P": P,
"Q": Q,
"R": R,
"S": S,
"T": T,
"U": U,
"R": R,
"S": S,
"T": T,
"U": U,
"V": V,
"W": W,
"X": X,
"Y": Y,
"Z": Z
}
# C struct redefinitions
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", PUL)]
class HardwareInput(ctypes.Structure):
_fields_ = [("uMsg", ctypes.c_ulong),
("wParamL", ctypes.c_short),
("wParamH", ctypes.c_ushort)]
class MouseInput(ctypes.Structure):
_fields_ = [("dx", ctypes.c_long),
("dy", ctypes.c_long),
("mouseData", ctypes.c_ulong),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", PUL)]
class Input_I(ctypes.Union):
_fields_ = [("ki", KeyBdInput),
("mi", MouseInput),
("hi", HardwareInput)]
class Input(ctypes.Structure):
_fields_ = [("type", ctypes.c_ulong),
("ii", Input_I)]
from ctypes import windll, Structure, c_long, byref
class POINT(Structure):
_fields_ = [("x", c_long), ("y", c_long)]
def queryMousePosition():
pt = POINT()
windll.user32.GetCursorPos(byref(pt))
return pt
# return { "x": pt.x, "y": pt.y}/
def click(x, y):
# convert to ctypes pixels
# x = int(x * 0.666)
# y = int(y * 0.666)
ctypes.windll.user32.SetCursorPos(x, y)
ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0) # left down
ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0) # left up
def moveMouseTo(x, y):
# convert to ctypes pixels
# x = int(x * 0.666)
# y = int(y * 0.666)
print(x, y)
ctypes.windll.user32.SetCursorPos(x, y)
# ctypes.windll.user32.mouse_event(2, 0, 0, 0, 0) # left down
# ctypes.windll.user32.mouse_event(4, 0, 0, 0, 0) # left up
def PressKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput(0, hexKeyCode, 0x0008, 0, ctypes.pointer(extra))
x = Input(ctypes.c_ulong(1), ii_)
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def ReleaseKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput(0, hexKeyCode, 0x0008 | 0x0002, 0, ctypes.pointer(extra))
x = Input(ctypes.c_ulong(1), ii_)
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def ClickKey(hexKeyCode):
PressKey(hexKeyCode)
ReleaseKey(hexKeyCode)