class Key_Mapping:
num1 = 0x02
num2 = 0x03
num3 = 0x04
num4 = 0x05
num5 = 0x06
num6 = 0x07
num7 = 0x08
num8 = 0x09
num9 = 0x0a
num0 = 0x0b
escape = 0x01
equal = 0x0d
backspace = 0x0e
tab = 0x0f
q = 0x10
w = 0x11
e = 0x12
r = 0x13
t = 0x14
y = 0x15
u = 0x16
i = 0x17
o = 0x18
p = 0x19
enter = 0x1c
lcontrol = 0x1d
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
shift = 0x36
multiply = 0x37
space = 0x39
capital = 0x3a
f1 = 0x3b
f2 = 0x3c
f3 = 0x3d
f4 = 0x3e
f5 = 0x3f
f6 = 0x40
f7 = 0x41
f8 = 0x42
f9 = 0x43
f10 = 0x44
numlock = 0x45
f11 = 0x57
f12 = 0x58
divide = 0xb5
home = 0xc7
up = 0xc8
prior = 0xc9
left = 0xcb
right = 0xcd
end = 0xcf
down = 0xd0
next = 0xd1
insert = 0xd2
delete = 0xd3
divide = 0xb5
home = 0xc7
up = 0xc8
prior = 0xc9
left = 0xcb
right = 0xcd
end = 0xcf
down = 0xd0
next = 0xd1
insert = 0xd2
delete = 0xd3
Simulate keyboard clicking , Release and so on
notes : Mainly used PressKey(), ReleaseKey()
import ctypes
import time
SendInput = ctypes.windll.user32.SendInput
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)]
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))
call Kyes.py file
notes :
The main quotation is Keys.py Of documents PressKey, ReleaseKey, Key_Mapping
Count down first , You need to move the mouse to the game window before the end , Click on it.
PressKey() Want to be with ReleaseKey() In combination with , See the code for details.
from Keys import PressKey, ReleaseKey, Key_Mapping
import time
i = 3
while i != 0:
print(“time:”, i)
time.sleep(0.5)
i -= 1
PressKey(Key_Mapping.w)
print(“start forward”)
time.sleep(3)
ReleaseKey(Key_Mapping.w)
print(“end forward”)
print(“start back”)
PressKey(Key_Mapping.s)