I'd like to do the same as this : How to use extended scancodes in SendInput in Python, using ctypes.
I can send regular scancodes with Sendinput, but I can't seem to send arrays of Input, thus failing to send extended scancodes.
So far, here's what I'm doing. Can anyone point me in the right direction ? This does nothing at all, I'd like it to press Right CTRL.
import ctypes
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 InputI(ctypes.Union):
_fields_ = [("ki", KeyBdInput),
("mi", MouseInput),
("hi", HardwareInput)]
class Input(ctypes.Structure):
_fields_ = [("type", ctypes.c_ulong),
("ii", InputI)]
Inputx = Input * 2 # to create an array of Input, as mentionned in ctypes documentation
def press(scan_code):
extra1 = ctypes.c_ulong(0)
ii1_ = InputI()
ii1_.ki = KeyBdInput(0, 0xE0, 0x0008, 0, ctypes.pointer(extra1))
x1 = Input(ctypes.c_ulong(1), ii1_)
extra2 = ctypes.c_ulong(0)
ii_2 = InputI()
ii_2.ki = KeyBdInput(1, scan_code, 0x0008, 0, ctypes.pointer(extra2))
x2 = Input(ctypes.c_ulong(1), ii_2)
x = Inputx(x1, x2)
ctypes.windll.user32.SendInput(2, ctypes.pointer(x), ctypes.sizeof(x))
press(0x1D)