Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. # http://www.gamespp.com/directx/directInputKeyboardScanCodes.html
  2.  
  3. import ctypes
  4. import time
  5.  
  6. SendInput = ctypes.windll.user32.SendInput
  7.  
  8. W = 0x11
  9. A = 0x1E
  10. S = 0x1F
  11. D = 0x20
  12. Z = 0x2C
  13. UP = 0xC8
  14. DOWN = 0xD0
  15. LEFT = 0xCB
  16. RIGHT = 0xCD
  17. ENTER = 0x1C
  18.  
  19. # C struct redefinitions
  20. PUL = ctypes.POINTER(ctypes.c_ulong)
  21. class KeyBdInput(ctypes.Structure):
  22. _fields_ = [("wVk", ctypes.c_ushort),
  23. ("wScan", ctypes.c_ushort),
  24. ("dwFlags", ctypes.c_ulong),
  25. ("time", ctypes.c_ulong),
  26. ("dwExtraInfo", PUL)]
  27.  
  28. class HardwareInput(ctypes.Structure):
  29. _fields_ = [("uMsg", ctypes.c_ulong),
  30. ("wParamL", ctypes.c_short),
  31. ("wParamH", ctypes.c_ushort)]
  32.  
  33. class MouseInput(ctypes.Structure):
  34. _fields_ = [("dx", ctypes.c_long),
  35. ("dy", ctypes.c_long),
  36. ("mouseData", ctypes.c_ulong),
  37. ("dwFlags", ctypes.c_ulong),
  38. ("time",ctypes.c_ulong),
  39. ("dwExtraInfo", PUL)]
  40.  
  41. class Input_I(ctypes.Union):
  42. _fields_ = [("ki", KeyBdInput),
  43. ("mi", MouseInput),
  44. ("hi", HardwareInput)]
  45.  
  46. class Input(ctypes.Structure):
  47. _fields_ = [("type", ctypes.c_ulong),
  48. ("ii", Input_I)]
  49.  
  50. # Actuals Functions
  51.  
  52. def pressKey(hexKeyCode):
  53. extra = ctypes.c_ulong(0)
  54. ii_ = Input_I()
  55. ii_.ki = KeyBdInput( 0, hexKeyCode, 0x0008, 0, ctypes.pointer(extra) )
  56. x = Input( ctypes.c_ulong(1), ii_ )
  57. ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
  58.  
  59. def releaseKey(hexKeyCode):
  60. extra = ctypes.c_ulong(0)
  61. ii_ = Input_I()
  62. ii_.ki = KeyBdInput( 0, hexKeyCode, 0x0008 | 0x0002, 0,
  63. ctypes.pointer(extra) )
  64. x = Input( ctypes.c_ulong(1), ii_ )
  65. ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
  66.  
  67.  
  68.  
  69. if __name__ == '__main__':
  70. while True:
  71.  
  72. time.sleep(1)
  73. pressKey(0x4C) # Pressing Num 5
  74. time.sleep(1)
  75. releaseKey(0x4C)
  76.  
  77. time.sleep(3)
  78. pressKey(0x1C) # Pressing Enter
  79. time.sleep(1)
  80. releaseKey(0x1C)
  81. time.sleep(18)
  82.  
  83.  
  84.  
  85.  
  86. pressKey(0xC9) # Pressing Page Up
  87. time.sleep(1)
  88. releaseKey(0xC9)
  89. time.sleep(18)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement