Unable to use certain keys on non-US keyboard layout #8033
Description
What version of MonoGame does the bug occur on:
- MonoGame 3.8.1
What operating system are you using:
- Windows
What MonoGame platform are you using:
- DesktopGL
So, this is the problem:
If you use the US
keyboard layout, everything is fine.
If you use the DE
keyboard layout, you cannot use these keys: ^ ß ´ ü ö ä #
Why? Because they are detected as Keys.None
.
The reason is, that they are not mapped in the KeyboardUtil.SDL
Dictionary.
The keys that the represent also aren't represented in the Keys
enum.
So, what is the solution?
Either add those keys to the Keys
enum and also add the mapping to the Dictionary.
Aha, but what about the other keyboard layouts? Well, it would have to be done for them all.
Sounds tedious? It certainly is.
So I would suggest a different approach.
ScanCodes to the rescue!
I have a PR prepared that remaps everything from the KeybaordUtil.SDL
Dictionary to their scancodes instead of keycodes.
This way all keys are usable on "all" keyboard layouts. I tested it with US
, DE
, FR
, RU
The downside? They are all mapped to the US
layout Keys enum.
Meaning, although you are pressing ^
on the DE
keyboard, it is detected as Keys.OemTilde
(~
)
Meaning, although you are pressing ö
on the DE
keyboard, it is detected as Keys.OemSemicolon
(;
)
You get the idea...
While this is not the perfect solution (and I don't know what the perfect solution would be, to be honest), this would certainly help to make supporting different keyboard layouts easier.
As it is now, even successful games like Stardew Valley have the bug that you cannot use ^ ß ´ ü ö ä #
as hotkeys on a german keyboard layout.
https://forums.stardewvalley.net/threads/bug-game-doesnt-recognise-keys-leads-to-issue-with-key-bindings-hotkeys.11695/
The Pull Request:
#8032
Foremost: On my Logitech G710+ I tested all keys on my keyboard and they are all mapped in my scancode list now.
However, there are a few keys (some seem to be duplicate?) from the keycode mapping that I couldn't find an equivalent scancode, maybe those are only present on special keyboards, like F13-F24?
List of the "problematic" keys:
I have mapped 1 of those keys, but they are present 2 times in the original keycode mapping. Not sure why
Add (I mapped 87)
Decimal (I mapped 99)
VolumeMute (I mapped 262)
I don't have those keys on my keyboard, so I couldn't map them.
BrowserBack
BrowserFavorites
BrowserForward
BrowserHome
BrowserRefresh
BrowserSearch
BrowserStop
F13
F14
F15
F16
F17
F18
F19
F20
F21
F22
F23
F24
LaunchMail
OemBackslash <-- this one should be easy to map for someone with an actual US keyboard
OemClear
SelectMedia
Sleep