Ejemplo n.º 1
0
    def ScanDevices(self):
        nDevices = UINT(0)
        if -1 == GetRawInputDeviceList(None, byref(nDevices),
                                       sizeof(RAWINPUTDEVICELIST)):
            raise WinError()
        rawInputDeviceList = (RAWINPUTDEVICELIST * nDevices.value)()
        if -1 == GetRawInputDeviceList(
                cast(rawInputDeviceList, PRAWINPUTDEVICELIST), byref(nDevices),
                sizeof(RAWINPUTDEVICELIST)):
            raise WinError()

        cbSize = UINT()
        for i in range(nDevices.value):
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICENAME, None, byref(cbSize))
            deviceName = create_unicode_buffer(cbSize.value)
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICENAME, byref(deviceName),
                                  byref(cbSize))
            ridDeviceInfo = RID_DEVICE_INFO()
            cbSize.value = ridDeviceInfo.cbSize = sizeof(RID_DEVICE_INFO)
            GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice,
                                  RIDI_DEVICEINFO, byref(ridDeviceInfo),
                                  byref(cbSize))
            if ridDeviceInfo.dwType != RIM_TYPEKEYBOARD:
                continue
            print "hDevice:", rawInputDeviceList[i].hDevice
            print "Type:", RIM_TYPES[rawInputDeviceList[i].dwType]
            print "DeviceName:", deviceName.value
            if ridDeviceInfo.dwType == RIM_TYPEHID:
                hid = ridDeviceInfo.hid
                print "dwVendorId: %04X" % hid.dwVendorId
                print "dwProductId: %04X" % hid.dwProductId
                print "dwVersionNumber: %04X" % hid.dwVersionNumber
                print "usUsagePage:", hid.usUsagePage
                print "usUsage:", hid.usUsage
            if ridDeviceInfo.dwType == RIM_TYPEKEYBOARD:
                kbd = ridDeviceInfo.keyboard
                print "dwType:", kbd.dwType
                print "dwSubType:", kbd.dwSubType
                print "dwKeyboardMode:", kbd.dwKeyboardMode
                print "dwNumberOfFunctionKeys:", kbd.dwNumberOfFunctionKeys
                print "dwNumberOfIndicators:", kbd.dwNumberOfIndicators
                print "dwNumberOfKeysTotal:", kbd.dwNumberOfKeysTotal
            if ridDeviceInfo.dwType == RIM_TYPEMOUSE:
                mouse = ridDeviceInfo.mouse
                print "dwId:", mouse.dwId
                print "dwNumberOfButtons:", mouse.dwNumberOfButtons
                print "dwSampleRate:", mouse.dwSampleRate
                print "fHasHorizontalWheel:", mouse.fHasHorizontalWheel
            print
Ejemplo n.º 2
0
 def OnRawInput(self, hwnd, mesg, wParam, lParam):
     pcbSize = UINT()
     GetRawInputData(
         lParam, RID_INPUT, None, byref(pcbSize), sizeof(RAWINPUTHEADER)
     )
     buf = create_string_buffer(pcbSize.value)
     GetRawInputData(
         lParam, RID_INPUT, buf, byref(pcbSize), sizeof(RAWINPUTHEADER)
     )
     pRawInput = cast(buf, POINTER(RAWINPUT))
     keyboard = pRawInput.contents.data.keyboard
     if keyboard.VKey == 0xFF:
         eg.eventThread.Call(eg.Print, "0xFF")
         return 0
      #print "Scan code:", keyboard.MakeCode
     info = ""
     mTime = time.clock()
     if keyboard.Message == WM_KEYDOWN:
         transition = "KEYDOWN"
     elif keyboard.Message == WM_KEYUP:
         transition = "KEYUP"
     else:
         transition = " %d" % keyboard.Message
     info = "%f " % mTime
     info += "RawI %s: %s(%d), " % (
         transition,
         VK_KEYS[keyboard.VKey],
         keyboard.VKey
     )
     if GetAsyncKeyState(162): #LCtrl
         info += "LCtrl "
     if GetAsyncKeyState(163): #RCtrl
         info += "RCtrl "
     info += "Scan: %d, " % keyboard.MakeCode
     info += "Extra: %d, " % keyboard.ExtraInformation
     info += "Device: %r, " % pRawInput.contents.header.hDevice
     #print "Flags:", keyboard.Flags
     rawKeyboardData = RawKeyboardData(
         keyboard.VKey,
         pRawInput.contents.header.hDevice,
         keyboard.Message in (WM_KEYDOWN, WM_SYSKEYDOWN),
         time.clock()
     )
     self.buf.append(rawKeyboardData)
     eg.eventThread.Call(eg.Print, info)
     if GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT:
         return DefWindowProc(hwnd, mesg, wParam, lParam)
     return 0