Paso 10: Programación (Python)
serial de importación
codecs de importación
ctypes de importación
tiempo de importación
de importación sueño
SendInput = ctypes.windll.user32.SendInput
PUL = ctypes. Pointer(ctypes.c_ulong)
clase KeyBdInput(ctypes. Estructura):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
("tiempo", ctypes.c_ulong),
("dwExtraInfo", PUL)]
clase HardwareInput(ctypes. Estructura):
_fields_ = [("uMsg", ctypes.c_ulong),
("wParamL", ctypes.c_short),
("wParamH", ctypes.c_ushort)]
clase MouseInput(ctypes. Estructura):
_fields_ = [("dx", ctypes.c_long),
("dy", ctypes.c_long),
("mouseData", ctypes.c_ulong),
("dwFlags", ctypes.c_ulong),
("time",ctypes.c_ulong),
("dwExtraInfo", PUL)]
clase Input_I(ctypes. Unión):
_fields_ = [("ki", KeyBdInput),
("mi", MouseInput),
("Hola", HardwareInput)]
clase de entrada (ctypes. Estructura):
_fields_ = [("tipo", ctypes.c_ulong),
("ii", Input_I)]
DEF PressKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.Ki = KeyBdInput (hexKeyCode, 0x48, 0, 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 (hexKeyCode, 0x48, 0x0002, 0, ctypes.pointer(extra))
x = Input (ctypes.c_ulong(1), ii_)
ctypes.windll.user32.SendInput (1, ctypes.pointer(x), ctypes.sizeof(x))
DEF PressW():
PressKey(0x57) #W
DEF ReleaseW():
ReleaseKey(0x57) #W
DEF PressA():
PressKey(0x41) #A
DEF ReleaseA():
ReleaseKey(0x41) #A
DEF PressS():
PressKey(0x53) #S
DEF ReleaseS():
ReleaseKey(0x53) #S
DEF PressD():
PressKey(0x44) #D
DEF ReleaseD():
ReleaseKey(0x44) #D
Puerto = "COM6"
ser = serial. Serial (puerto, 9600, timeout = 0)
Aunque la verdad:
#data = ser.read(9999)
línea = ser.readline()
Si línea:
Imprimir (' Got:', línea)
Si línea == b '0\r\n':
Print('W_UP')
PressW()
línea de Elif == b '1\r\n':
Print('W_DOWN')
ReleaseW()
Si línea == b '2\r\n':
Print('S_UP')
PressS()
línea de Elif == b '3\r\n':
Print('S_DOWN')
ReleaseS()
Si línea == b '4\r\n':
Print('A_UP')
PressA()
línea de Elif == b '5\r\n':
Print('A_DOWN')
ReleaseA()
Si línea == b '6\r\n':
Print('D_UP')
PressD()
línea de Elif == b '7\r\n':
Print('D_DOWN')
ReleaseD()
Sleep(0.0125)
Print('0')
ser.Close()