forked from GrayTempest-400/warthunder-cv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresskey.py
76 lines (50 loc) · 1.65 KB
/
presskey.py
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
import time
from ctypes import POINTER, c_ulong, Structure, c_ushort, c_short, c_long, byref, windll, pointer, sizeof, Union
SendInput = windll.user32.SendInput
PUL = POINTER(c_ulong)
class KeyBdInput(Structure):
_fields_ = [("wVk", c_ushort), ("wScan", c_ushort), ("dwFlags", c_ulong),
("time", c_ulong), ("dwExtraInfo", PUL)]
class HardwareInput(Structure):
_fields_ = [("uMsg", c_ulong), ("wParamL", c_short), ("wParamH", c_ushort)]
class MouseInput(Structure):
_fields_ = [("dx", c_long), ("dy", c_long), ("mouseData", c_ulong),
("dwFlags", c_ulong), ("time", c_ulong), ("dwExtraInfo", PUL)]
class Input_I(Union):
_fields_ = [("ki", KeyBdInput), ("mi", MouseInput), ("hi", HardwareInput)]
class Input(Structure):
_fields_ = [("type", c_ulong), ("ii", Input_I)]
# Actuals Functions
def PressKey(hexKeyCode):
extra = c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput(0, hexKeyCode, 0x0008, 0, pointer(extra))
x = Input(c_ulong(1), ii_)
windll.user32.SendInput(1, pointer(x), sizeof(x))
def ReleaseKey(hexKeyCode):
extra = c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput(0, hexKeyCode, 0x0008 | 0x0002, 0, pointer(extra))
x = Input(c_ulong(1), ii_)
windll.user32.SendInput(1, pointer(x), sizeof(x))
def press(k):
PressKey(k)
time.sleep(0.1)
ReleaseKey(k)
time.sleep(0.4)
def hold(k, t):
PressKey(k)
time.sleep(t)
ReleaseKey(k)
time.sleep(0.5)
def key_down(k):
PressKey(k)
time.sleep(0.1)
def key_up(k):
ReleaseKey(k)
time.sleep(0.1)
def wtpress(k):
PressKey(k)
time.sleep(0.1)
ReleaseKey(k)
time.sleep(1.4)