Is there support for keyboard key position?

(JP Moresmau) #1

Hello, I use a French keyboard, so in the Pong tutorial, the W and S key are not logical (on a French keyboard the W is on the bottom row). Is there any kind of support for specifying keys based on the position, instead of the real character value? Or in a production ready game would we expect the configuration of keys to be configurable?

Thanks!

JP

1 Like
(Azriel Hoh) #2

Yeap, there’s ScanCode, which should be position based – we back onto winit. Unfortunately I don’t know how to figure out the scan code just by looking at the keyboard, but I think one could write a little app that prints the scan code when the button is pressed.

The input configuration would look something like this:

(
    axes: {
        "x_axis": Emulated(
            pos: Button(81),
            neg: Button(83),
        ),
        "y_axis": Emulated(
            pos: Button(82),
            neg: Button(84),
        ),
    },
    actions: {
        "attack": Button(123),
    },
)
3 Likes
(JP Moresmau) #3

Thanks a million for the answer. Button does not work in binding.ron, you have to specify ScanCode. The codes at this page: https://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html seem to work for my machine. So for the Pong tutorial I have bindings.ron as:

(
  axes: {
    "left_paddle": Emulated(pos: ScanCode(0x11), neg: ScanCode(0x1F)),
    "right_paddle": Emulated(pos: Key(Up), neg: Key(Down)),
  },
  actions: {},
)

0x11 is W on a US keyboard and Z on my french keyboard, 0X1F is S. So the keys are in the right position on both keyboards.

Cheers,

JP

4 Likes