Determine the name / key code of an unknown (0x0) key
I wrote some code that detects which key was pressed.
@Override
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
String name = KeyEvent.getKeyText(code);
tArea.append(name + " pressed\n");
}
This code works fine. But on my keyboard, it's a circle that can be used to stop a song playing in the media plan, start a song (as well as pause a song), skip to the next song, and go back to the previous song. This keyboard has many keys. But when I click a button from that circle, it says:
Unknown keycode: 0x0 pressed
...
Is there a way to get this key? I need to know what it is, since I am writing a program that should automatically press these keys.
Thank you in advance
source to share
To get these key events, you need to use the getExtendedKeyCode()
.
Please note that Javadoc says that you do not get an event KEY_TYPED
for them, but KEY_PRESSED
and KEY_RELEASED
because KEY_TYPED
for things that can be included in Unicode characters, what it can not.
If the extended key code is still not enough to determine what you are pressing, then you need to resort to the scan code that is present in KeyEvent
but not available because it is a private field. In this This list key codes can help you. You are dealing with something in the "non-display" list.
source to share