Search code examples
c++windows-7hidrfid

Can I specify which HID my C++ program listens to


I am trying to create an application that reads keyboard input from a HID. The OS I am trying to acheive this on is Windows 7. In what way would I specify to my program that it needs to listen to just one HID device (I have a normal keyboard, and an RFID reader as my two devices) Could some one tell me the best route to take if I wanted to just listen to one HID and ignore other keystrokes (From the keyboard)


Solution

  • Did you register for HID input with RegisterRawInputDevices() ? Because in that case, you tell Windows for which devices you want "raw" input.

    [edit] Rough sketch:

    int count = 0;
    GetRawInputDeviceList(0, &count, sizeof(RAWINPUTDEVICE);
    std::vector<RAWINPUTDEVICE> devs(count);
    GetRawInputDeviceList(&devs[0], &count, sizeof(RAWINPUTDEVICE);
    // Select device(s) you want
    RegisterRawInputDevices(&devs[0], &count, sizeof(RAWINPUTDEVICE);