2

This question is a possible duplicate of this and this thread. But since none of them have provided a clear solution for my problem, I'm asking it again.

My required task is to connect 2 Keyboards via USB and then manage the inputs of each Keyboard separately through a Java Application. This requirement has been answered into some progress in the first thread I have mentioned above by @nan but his solution did not work accurately for me. You can find his blog post on his solution for this here. He has done the solution using the java-hid-api and it seems accurate and working.

However the point I am stuck in it is at opening the HID Device. When I try to open the Device using the HIDManager using either the openByPath() or the openById() methods it returns only null and therefore it throws the NullPointerException. it is the same when I try it using the open() method of HIDDeviceInfo. this issue is listed in the java-hid-api page too but so far no one seems to have provided a working solution.

The OS I'm working on is Windows 7 32-bit

Here are all the 3 attempts I've made to open the HID Device

  1. HIDDevice hidDevice = HIDManager.getInstance().openByPath(hidDeviceInfo.getPath());

  2. HIDDevice hidDevice = HIDManager.getInstance().openById(hidDeviceInfo.getVendor_id(), hidDeviceInfo.getProduct_id(), hidDeviceInfo.getSerial_number());

  3. HIDDevice hidDevice = hidDeviceInfo.open();

Has anyone been able to get through this problem? If so your help is highly appreciated.

Thank you!

Update 1: I just found out that this task could be accomplished with JInput, according to the answer provided by @paul-whelan in this thread. I am going to try it now but I'm stating here first seeking for any confirmation or a guide on how to do it if anyone already knows and have accomplished it.

Community
  • 1
  • 1
RocketRuwan
  • 223
  • 1
  • 3
  • 14
  • For the sake of completeness: This seems to be a Windows-Issue according to the Issue-Tracker of both the C/C++ HID API and the Java Wrapper for the HID API. There is an unofficial patch for the C/C++ Implementation which solves this problem (at least it worked for me): http://angryelectron.com/javahidapi-nihardwareservice/ One can then rebuild the Java Wrapper with the patched Version (or you can directly Download the *.jar from the website above) –  Apr 15 '14 at 08:12

1 Answers1

0

This is what you do to initialize the library:

ClassPathLibraryLoader.loadNativeHIDLibrary();
HIDManager hm=HIDManager.getInstance();

Then you can read the devices etc:

HIDDeviceInfo[] dvl = hm.listDevices();
for (HIDDeviceInfo dv:dvl){
    System.out.println(dv.getManufacturer_string());        
}
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38