I would like to write an application where the keybindings are specific to the location of the key on the keyboard, not the character they are mapped to. For example, the key that is between t and u on a US keyboard should perform a specific function, regardless of whether it is Y as it is in the US or Z as it is in Germany.
I think the way to do this would be to get the actual scan code given by the keyboard to the OS to represent the key that was pressed. How can I do this in java?
Or is there another way to achieve the same functionality?
解决方案
As MadProgrammer said: You have to use JNA or JNI. You can also have a look at those projects:
(Windows only)
JIntellitype is a Java API for interacting with Microsoft Intellitype
commands as well as registering for Global Hotkeys in your Java
application. The API is a Java JNI library that uses a C++ DLL to do
all the communication with Windows.
There are similar projects Linux and Mac OS X.
(Windows, Linux and Mac OS?)
JNativeHook is a library to provide global keyboard and mouse
listeners for Java. This will allow you to listen for global shortcuts
or mouse motion that would otherwise be impossible using pure Java. To
accomplish this task, JNativeHook leverages platform dependent native
code through Java's native interface to create low level system wide
hooks and deliver those events to your application.
Windows only, capable of Win 7 / 8 (32 and 64 bit)