Monogame: [Keyboard - Azerty] Some keys not recognized

Created on 17 May 2017  路  22Comments  路  Source: MonoGame/MonoGame

Hello

I have an azerty keyboard, most of the keys are not recognized, and some of them are mapped to the wrong values

chrome_2017-05-17_08-41-24

Legend:
Green: incorect key returned
Pink: Not recognized at all, return "None"

OS: Windows 10 x64
MonoGame: 3.6 (DesktopGL from nuget)

Input

Most helpful comment

I can confirm the layout issues @BaseCrosser posted, but I can't reproduce @Scellow's ones. Returned key is always Keys.None for the red keys.
I'm on a FR-fr keyboard.

Also related: supporting non latin keyboard is an another issue.

I'm in for adding these azerty keys to the Keys enum, but regarding future versions of MonoGame, we should look into working with raw keycodes (or something like an external keymap file to allow players to customize their bindings, which would support any kind of keyboard if we go with raw codes).

All 22 comments

Hello,

This has to do with the way openTK handles keyboard input.
More information in #3836.

Edit: I tested this myself and my results are a little bit different.
480px-belgian_keyboard_layout

Red: Returns "None"
Yellow: Returns incorrectly. In my case the "AltGr" returns "LeftControl + RightAlt". If I hold "AltGr" and then press "LeftControl", "LeftControl" dissapears.

OS: Windows 10 x64
MonoGame: 3.7.0.379 (DesktopGL Nuget)

Latest MG DesktopGL does not use OpenTK, it uses SDL. A dictionary lookup is used to translate reported SDL keys to the XNA key mapping here. Maybe some entries are missing/incorrect. Some of the keys you report are not detected are in the mapping though, so it could be a bug in SDL. It would be awesome if someone could log SDL key down events and check if they're wrong or if we just need to add some mappings to the dict used for translating to XNA Keys.

We're using the SDL Keycode as input to that mapping to XNA Keys mapping function. SDL Keycode values are supposed to have already taken the user's keyboard layout into account. @Scellow or @BaseCrosser, are you able to confirm that the SDL Keycode being passed to that ToXna function is the incorrect or correct for the key being pressed?

I have checked the key codes that are passed to the ToXna() function.

Here are my results:
2ab28e4a-3afe-11e7-8d14-7574737ec138

All these blue numbers are not present in the SDL to Xna Key mapping Dictionary

"AltGr" passes two different keycodes to ToXna().
1073742048 for "LeftControl" and 1073742054 for "RighAlt".

Thanks @BaseCrosser! There are no entries in the XNA Keys enumeration for those keys. Not sure what XNA does in this case. We could add entries to the Keys enumeration for these keys @KonajuGames.

I'm open to a proposal to add those key to our Keys enum.

It would be good if @Scellow could also test the key codes since his/her results differ a bit from mine.
Which keys are returning "None" and which are returning the wrong key.

Also there is still the problem of "AltGr" returning two keys instead of one.

I can confirm the layout issues @BaseCrosser posted, but I can't reproduce @Scellow's ones. Returned key is always Keys.None for the red keys.
I'm on a FR-fr keyboard.

Also related: supporting non latin keyboard is an another issue.

I'm in for adding these azerty keys to the Keys enum, but regarding future versions of MonoGame, we should look into working with raw keycodes (or something like an external keymap file to allow players to customize their bindings, which would support any kind of keyboard if we go with raw codes).

The OS already provides the function of mapping of keyboard scan codes to keys using the active keyboard layout, and this is what SDL would be using behind the scenes. We should not be re-implementing that mapping functionality.

The XNA Keys enumeration appears to be an attempt to mix keyboard scan codes and key codes into one enumeration. SDL does it better by returning both the scan code and the key code in separate member fields for each key press.

So if we add the missing code enumeration for each keyboard layout, we're good to go with any kind of keyboard? Chinese and Russian keyboards concern me.

That's why mixing scan codes and key codes is not a good idea. There are a limited number of scan codes, but a far wider ranger of key codes dependent on keyboard layout.

Good to know, and way to go.

I will only chime in to say I have no clue what the right choice is here... i'll leave this to @KonajuGames to define. We just need to ensure we make the correct fix and consider all the possibilities so we don't have to reverse course on this later.

Oops my bad i colorized more keys than needed

This is pretty serious issue since it makes typing on AZERTY a real pain

I also trying to revert to 3.5.1 but it looks like it doesn't care about my keyboard layout, everything seems to be QWERTY

We're using the SDL Keycode as input to that mapping to XNA Keys mapping function. SDL Keycode values are supposed to have already taken the user's keyboard layout into account. @Scellow or @BaseCrosser, are you able to confirm that the SDL Keycode being passed to that ToXna function is the incorrect or correct for the key being pressed?

I don't understand, what do you want me to do ?

I don't understand, what do you want me to do ?

For the green or pink keys you show above, what is the SDL Keycode being passed to the ToXna() function?

Oh, ok i'll clone the repo and test this!

Looks like it is tedious to do for each key individualy, since most of the keys from 1-0 needs to be used with MAJ or ALT Gr modifiers

And i checked here:

For most characters, there are no scan codes available since they are not physical key, only keycode: https://wiki.libsdl.org/SDL_Scancode

eg: &茅"'(-猫_莽脿)=~#{[|`\^@]}

So mapping the scan code is not the right choice, need to find something else i think

What about this: https://wiki.libsdl.org/SDL_GetKeyName

So we get the char, then convert the char directly to Xna KeyCode ?

So what about this issue?

Reverting to 3.5.1 completly ignore the keyboard layout (DesktopGL/Windows)

Hi, any update on this bug ? I really need to use a french layout . Thanks

Was this page helpful?
0 / 5 - 0 ratings