Advertisement
Guest User

raw_input.py

a guest
Aug 8th, 2011
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.89 KB | None | 0 0
  1. from ctypes import *
  2. from ctypes.wintypes import *
  3. #####################################################################################
  4.  
  5. class RawInputError (RuntimeError) :
  6.     """ RawInput Errors """
  7.  
  8. class RAWINPUTDEVICE (Structure) :
  9.     _fields_ = [
  10.         ("usUsagePage", WORD),
  11.         ("usUsage",     WORD),
  12.         ("dwFlags",     DWORD),
  13.         ("hwndTarget",  HWND),
  14.     ]
  15.  
  16. class RAWINPUTDEVICELIST (Structure) :
  17.     _fields_ = [
  18.         ("hDevice", HANDLE),
  19.         ("dwType",  DWORD),
  20.     ]
  21.  
  22. class RAWINPUTHEADER (Structure) :
  23.     _fields_ = [
  24.         ("dwType",  DWORD),
  25.         ("dwSize",  DWORD),
  26.         ("hDevice", HANDLE),
  27.         ("wParam",  WPARAM),
  28.     ]
  29.  
  30. class RAWMOUSE (Structure) :
  31.     class _U1 (Union) :
  32.         class _S2 (Structure) :
  33.             _fields_ = [
  34.                 ("usButtonFlags", WORD),
  35.                 ("usButtonData",  SHORT),
  36.             ]
  37.         _fields_ = [
  38.             ("ulButtons", ULONG),
  39.             ("_s2",       _S2),
  40.         ]
  41.  
  42.     _fields_ = [
  43.         ("usFlags",            WORD),
  44.         ("_u1",                _U1),
  45.         ("ulRawButtons",       ULONG),
  46.         ("lLastX",             LONG),
  47.         ("lLastY",             LONG),
  48.         ("ulExtraInformation", ULONG),
  49.     ]
  50.     _anonymous_ = ("_u1", )
  51.  
  52. class RAWKEYBOARD (Structure) :
  53.     _fields_ = [
  54.         ("MakeCode",         WORD),
  55.         ("Flags",            WORD),
  56.         ("Reserved",         WORD),
  57.         ("VKey",             WORD),
  58.         ("Message",          UINT),
  59.         ("ExtraInformation", ULONG),
  60.     ]
  61.  
  62. class RAWHID (Structure) :
  63.     _fields_ = [
  64.         ("dwSizeHid", DWORD),
  65.         ("dwCount",   DWORD),
  66.         ("bRawData",  BYTE),
  67.     ]
  68.  
  69. class RAWINPUT (Structure) :
  70.     class _U1 (Union) :
  71.         _fields_ = [
  72.             ("mouse",    RAWMOUSE),
  73.             ("keyboard", RAWKEYBOARD),
  74.             ("hid",      RAWHID),
  75.         ]
  76.  
  77.     _fields_ = [
  78.         ("header",  RAWINPUTHEADER),
  79.         ("_u1",     _U1),
  80.         ("hDevice", HANDLE),
  81.         ("wParam",  WPARAM),
  82.     ]
  83.     _anonymous_ = ("_u1", )
  84.  
  85. class RID_DEVICE_INFO_MOUSE (Structure) :
  86.     _fields_ = [
  87.         ("dwId",              DWORD),
  88.         ("dwNumberOfButtons", DWORD),
  89.         ("dwSampleRate",      DWORD),
  90.     ]
  91.  
  92. class RID_DEVICE_INFO_KEYBOARD (Structure) :
  93.     _fields_ = [
  94.         ("dwType",                 DWORD),
  95.         ("dwSubType",              DWORD),
  96.         ("dwKeyboardMode",         DWORD),
  97.         ("dwNumberOfFunctionKeys", DWORD),
  98.         ("dwNumberOfIndicators",   DWORD),
  99.         ("dwNumberOfKeysTotal",    DWORD),
  100.     ]
  101.  
  102. class RID_DEVICE_INFO_HID (Structure) :
  103.     _fields_ = [
  104.         ("dwVendorId",      DWORD),
  105.         ("dwProductId",     DWORD),
  106.         ("dwVersionNumber", DWORD),
  107.         ("usUsagePage",     USHORT),
  108.         ("usUsage",         USHORT),
  109.     ]
  110.  
  111. class RID_DEVICE_INFO (Structure) :
  112.     class _U1 (Union) :
  113.         _fields_ = [
  114.             ("mouse",    RID_DEVICE_INFO_MOUSE),
  115.             ("keyboard", RID_DEVICE_INFO_KEYBOARD),
  116.             ("hid",      RID_DEVICE_INFO_HID),
  117.         ]
  118.  
  119.     _fields_ = [
  120.         ("cbSize", DWORD),
  121.         ("dwType", DWORD),
  122.         ("_u1",    _U1),
  123.     ]
  124.     _anonymous_ = ("_u1", )
  125. #####################################################################################
  126.  
  127. RIDEV_REMOVE       = 0x00000001
  128. RIDEV_EXCLUDE      = 0x00000010
  129. RIDEV_PAGEONLY     = 0x00000020
  130. RIDEV_NOLEGACY     = 0x00000030
  131. RIDEV_INPUTSINK    = 0x00000100
  132. RIDEV_CAPTUREMOUSE = 0x00000200 # effective when mouse nolegacy is specified, otherwise it would be an error
  133. RIDEV_NOHOTKEYS    = 0x00000200 # effective for keyboard.
  134. RIDEV_APPKEYS      = 0x00000400 # effective for keyboard.
  135. RIDEV_EXMODEMASK   = 0x000000F0
  136.  
  137. RIDI_PREPARSEDDATA = 0x20000005
  138. RIDI_DEVICENAME    = 0x20000007 # the return valus is the character length, not the byte size
  139. RIDI_DEVICEINFO    = 0x2000000b
  140.  
  141. RID_INPUT  = 0x10000003
  142. RID_HEADER = 0x10000005
  143.  
  144. RIM_TYPEMOUSE      = 0
  145. RIM_TYPEKEYBOARD   = 1
  146. RIM_TYPEHID        = 2
  147.  
  148. RI_MOUSE_LEFT_BUTTON_DOWN   = 0x0001 # Left Button changed to down.
  149. RI_MOUSE_LEFT_BUTTON_UP     = 0x0002 # Left Button changed to up.
  150. RI_MOUSE_RIGHT_BUTTON_DOWN  = 0x0004 # Right Button changed to down.
  151. RI_MOUSE_RIGHT_BUTTON_UP    = 0x0008 # Right Button changed to up.
  152. RI_MOUSE_MIDDLE_BUTTON_DOWN = 0x0010 # Middle Button changed to down.
  153. RI_MOUSE_MIDDLE_BUTTON_UP   = 0x0020 # Middle Button changed to up.
  154.  
  155. RI_MOUSE_WHEEL = 0x0400
  156.  
  157. MOUSE_MOVE_RELATIVE      = 0
  158. MOUSE_MOVE_ABSOLUTE      = 1
  159. MOUSE_VIRTUAL_DESKTOP    = 0x02 # the coordinates are mapped to the virtual desktop
  160. MOUSE_ATTRIBUTES_CHANGED = 0x04 # requery for mouse attributes
  161. #####################################################################################
  162.  
  163. RegisterRawInputDevices = windll.user32.RegisterRawInputDevices
  164. GetRawInputData         = windll.user32.GetRawInputData
  165. GetRawInputDeviceList   = windll.user32.GetRawInputDeviceList
  166. GetRawInputDeviceInfo   = windll.user32.GetRawInputDeviceInfoA
  167. #################################### End Of File ####################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement