KeyInput for i18n keyboards?

I’m trying to add this cool console to my game:

This console shows up by pressing the grave key, which in US keyboards is on the top left corner.

However, on my keyboard the KeyInput.KEY_GRAVE is somewhere near the “enter” key, which is not what I want (on my top left corner I have a backslash instead).
Is there a way to map a key ‘position’ so that it works regardless of locale? I remember it worked correctly with Quake…

The physical key ‘position’ exists only in the real world I’m afraid. The OS only receives the keycode from the keyboard driver.

If you want to map the button under escape in your application you’ll have to either

  • Force the keyboard layout (to be US for example), then map the grave key as normal

or

  • Detect the current keyboard layout and the rebind which key triggers your call-to-action for the console

OK, done with this:

Cool.

Though as an added thought, it may be possible to use keyboard “scancodes” (these represent a grid on a keyboard) but it depends what the keyboard driver will give you at the mighty high level of java.

If this is not exposed, you would have to use JNI to hook into the keyboard driver.

The scancode you’re looking for is 35 for the grave key, (assuming a USB keyboard/encoding)

Grave key is 29 for type 1 and 0e for type 2 or 3. This will be independent of keyboard language

1 Like

This probably explains why DOS games worked :frowning:

Once we switch to LWJGL3, there will be more information provided with key events, possibly some that are independent of key layout.