-
Notifications
You must be signed in to change notification settings - Fork 92
/
directkeys.py
201 lines (162 loc) · 3.94 KB
/
directkeys.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
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
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 8 10:37:50 2020
@author: pang
"""
import ctypes
import time
SendInput = ctypes.windll.user32.SendInput
W = 0x11
A = 0x1E
S = 0x1F
D = 0x20
M = 0x32
J = 0x24
K = 0x25
LSHIFT = 0x2A
R = 0x13#用R代替识破
V = 0x2F
Q = 0x10
I = 0x17
O = 0x18
P = 0x19
C = 0x2E
F = 0x21
up = 0xC8
down = 0xD0
left = 0xCB
right = 0xCD
esc = 0x01
# 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)]
# Actuals Functions
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 defense():
PressKey(M)
time.sleep(0.05)
ReleaseKey(M)
#time.sleep(0.1)
def attack():
PressKey(J)
time.sleep(0.05)
ReleaseKey(J)
#time.sleep(0.1)
def go_forward():
PressKey(W)
time.sleep(0.4)
ReleaseKey(W)
def go_back():
PressKey(S)
time.sleep(0.4)
ReleaseKey(S)
def go_left():
PressKey(A)
time.sleep(0.4)
ReleaseKey(A)
def go_right():
PressKey(D)
time.sleep(0.4)
ReleaseKey(D)
def jump():
PressKey(K)
time.sleep(0.1)
ReleaseKey(K)
#time.sleep(0.1)
def dodge():#闪避
PressKey(R)
time.sleep(0.1)
ReleaseKey(R)
#time.sleep(0.1)
def lock_vision():
PressKey(V)
time.sleep(0.3)
ReleaseKey(V)
time.sleep(0.1)
def go_forward_QL(t):
PressKey(W)
time.sleep(t)
ReleaseKey(W)
def turn_left(t):
PressKey(left)
time.sleep(t)
ReleaseKey(left)
def turn_up(t):
PressKey(up)
time.sleep(t)
ReleaseKey(up)
def turn_right(t):
PressKey(right)
time.sleep(t)
ReleaseKey(right)
def F_go():
PressKey(F)
time.sleep(0.5)
ReleaseKey(F)
def forward_jump(t):
PressKey(W)
time.sleep(t)
PressKey(K)
ReleaseKey(W)
ReleaseKey(K)
def press_esc():
PressKey(esc)
time.sleep(0.3)
ReleaseKey(esc)
def dead():
PressKey(M)
time.sleep(0.5)
ReleaseKey(M)
if __name__ == '__main__':
time.sleep(5)
time1 = time.time()
while(True):
if abs(time.time()-time1) > 5:
break
else:
PressKey(M)
time.sleep(0.1)
ReleaseKey(M)
time.sleep(0.2)
PressKey(W)
time.sleep(0.4)
ReleaseKey(W)
time.sleep(1)
PressKey(J)
time.sleep(0.1)
ReleaseKey(J)
time.sleep(1)