I hope that this question hasn’t been asked already, but I was looking for a solution of my problem and I didn’t found anything helpful for me.
I’m writing a Java Application, where the user can control the App via his keyboard. The problem is, that I need many different input keys. So I also have to use the special char keys. But my problem is, that I can’t code the whole thing for every keyboard again.
So my question is, is there a way to determine the place of a given key on the keyboard. It would be very good if someone would know how to do this.
Thanks in advance,
Leo
A keyboard only sends key codes to the underlying stack. It’s up to the OS and software to figure out how to use this. Now perhaps the hardware does have a simple code that relies on location and there’s some translation going on to turn this into a usable key code for applications. I reckon this must be the case since the layout can be chosen from OS. But that doesn’t seem like the kind of low-level stuff you’d have access to in Java, short of using JNI.
Originating from a KeyListener, you can capture KeyEvents. I’d suggest you look into the doc, fields and methods of that class and maybe make a small test app that captures such events and prints the results of various methods out. Maybe you can find some common ground.
If there’s no straightforward way of doing this, perhaps it’s best to have some sort of translation table scheme that standardizes the input for the most common layouts, like Qwerty and Azerty. That should do it for most users and since you wish to rely on absolute positioning, requiring one of a small set of layouts doesn’t seem unacceptable. Users can change the layout in the OS.
If you happen to be making a game, maybe create some huge control deck that people will be forced to buy to get the best experience. Extra money! 😀