Newt, wrong keycode for # key?
Posted by Cygnus on Dec 02, 2014; 12:43pm
URL: https://forum.jogamp.org/Newt-wrong-keycode-for-key-tp4033690.html
Hello, I work on a team that uses JOGL and Newt for a Java game.
We received a report from players about the key bindings having issues with the “#” key, it registers as a backslash with the keybind system. At first we thought it was maybe down to keyboard layout but after testing it became clear the problem is not caused by the layout and only affects Newt (keycode correctly returns 520 in AWT).
I put together a simple Newt test application with a basic KeyListener:
public class TestKeyListener implements KeyListener {
@Override
public void keyReleased(KeyEvent e) {}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("keyCode: " + e.getKeyCode() + ", keyChar: "+ e.getKeyChar() + ", modifiers: " + e.getModifiers() + ", keySymbol: " + e.getKeySymbol());
}
}
I then tried it on a couple of different machines (Windows 7 and Mac OS X Yosemite) to check it wasn't a problem with one specific platform. The result for the “#” key always returned:
keyCode: 92, keyChar: #, modifiers: 0, keySymbol: 39
The character is correct but keyCode 92 matches VK_BACK_SLASH (0x5C). The VK_NUMBER_SIGN (0x23) is hard defined 35 so the result this really doesn't seem to make sense, even the keySymbol if that was intended to be used instead doesn't match up.
On the flip side backslash (like most keys) behaves correctly:
keyCode: 92, keyChar: \, modifiers: 0, keySymbol: 92
I traced it as far back as I could with the Eclipse debugger on a Windows machine, it comes through from the native side to WindowDriver.sendKeyEvent(short, int, short, short, char) with keyCode 92 already.
I've not seen a bug report for it so I'm unsure if this behaviour is intentional but it seems a strange thing to chose to do.