Java Native Access (JNA) allows you to access the basic levels of operating systems using Pure Java. Here you can access the JNA project here .
In addition, I found a sample that uses JNA to connect to a hardware keyboard to listen for keystrokes. I think this one is what you are looking for.
If this is not what you are looking for, then you can definitely look over the link and implement your own.
source share