I am working on a small project: I need to take the input from a number pad and run macros based off which key was pressed. However, I'm having some difficulty reading from the number pad specifically. stdin simply reads from the key inputs; I actually need the raw data output from the number pad USB device. The number pad is a separate device from the keyboard.
My research indicates I'll have to write a device driver for it using the Windows DDK, but this doesn't quite make sense to me. I want to select a different USB input device as a keyboard - this shouldn't require a new driver, as I'll still be using it as a keyboard. I just need to change the scope of my input stream to just the USB device.
I could also be missing some key piece of information. So, is there a simple way to do this?
-
stackoverflow.com/questions/7373247/…akira– akira2013年01月09日 07:11:48 +00:00Commented Jan 9, 2013 at 7:11
-
Post as answer for accept.user1131435– user11314352013年01月09日 08:14:40 +00:00Commented Jan 9, 2013 at 8:14
-
If memory serves, you can use DirectInput on Windows to read from a specific keyboard. msdn.microsoft.com/en-us/library/ee417799%28v=VS.85%29.aspx YMMVselbie– selbie2013年01月10日 12:33:12 +00:00Commented Jan 10, 2013 at 12:33
1 Answer 1
You have to read the RAW usb-events from the right device. You can write that code either yourself by reading 'Raw Input' or 'Human Interface Devices Reference' (part of the Windows Driver Kit) on MSDN.
Or you could use libusb, as mentioned on Read Raw USB Input on Windows, which hides a lot of the crufty details under a neat API. A rough idea is to:
- get the list of devices via
libusb_get_device_list() - find the keyboard you are interested in via
libusb_get_device_descriptor(), check theexamples/listdevs.cfile for a clue about how to do that. - open the device via
libusb_open() - do your magic (i think polling for events will fit)
- and .. close the device at the end
Side note: libusb flawlessly built on Windows8 with VS2012 Express + WDK8.