Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Separate Input of Two Separate Keyboards

Tags:

java

usb

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!

like image 691
user1383359 Avatar asked May 09 '12 01:05

user1383359


Video Answer


2 Answers

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.

like image 53
Simon Avatar answered Sep 27 '22 23:09

Simon


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.

like image 41
RocketRuwan Avatar answered Sep 27 '22 22:09

RocketRuwan