I have two USB keyboards plugged into the same machine. I am developing a Java application. Is there anyway to allow the Java Application to separate out which USB keyboard it came from? (I.e. is there something like http://docs.oracle.com/javase/6/docs/api/java/awt/event/KeyEvent.html but with a USB parameter so I can know which USB device it came from?)
Thanks!
This is not possible with Java alone.
But there are 3rd party tools that can remap the keys of a keyboard. HID macros is one application. But it only works with key presses, not key-up and -down events. This limits it's usefulness but might be enough for your usecase.
If you want to dig deeper you need to use the RAW Input API on Windows to do what you want. There's already a nice example on code project titled Using Raw Input from C# to handle multiple keyboards that sheds some light on the correct API usage.
I might be too late to answer here since this question is an old one. But since I have been directed here when I was looking for the same requirement, I will mention a solution I found on another thread for the help of those who will be directed here in the future, seeking help for the same requirement. @nan has given a solution for this using the java-hid-api and you can find his answer here. He has also written a clear and step by step post on how to do it in his blog.
However I must say that I have tried this but still I haven't been successful at it as the HIDManager
returns null when trying to open the HID by either the path or the id. It is the same when tried to open()
using HIDDeviceInfo
. This issue is listed in the java hid api page too but it seems no one has been able to provide a working solution so far. So if there is anyone who has been able to bypass this issue. Please do share.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With