And if I press K or L or U then I will see that I pressed “K” or “L” or “U”
But if I press Ö or Ä or Ü or # or ^ then it will say that I pressed “None”.
If I press Ö and # together then it will also just count as 1 key press (accoding to GetPressedKeys().Length)
Is there any known way to work around this issue?
It seems like a really breaking issue for me, so surely there’s a good solution for this problem, right?
I am using the OpenGL MonoGame variant if that matters
The problem with the ‘^’ key is, that it is on different positions for almost every language out there also being a secondary for a different other key … I once stumbled upon some technical reason but forgot it.
(edit: on german layouts, the ‘^’ is left of the ‘1’ key, afaik it’s ‘~’ on us layout?)
So while I would be interested if there is an easy way to do it - what I did is just use a different key. Like the Pause Key which is standardized and its almost never been used for anything nowadays
@reiti.net thanks, your logo is nice too
yeah, I realize for this specific function I could just use another key, but I really dislike the thought of players being unable to bind anything to ^ ü ö ä # or ´ just because I can’t detect those key presses in MonoGame.
Well MonoGame detects that a key is pressed, but refuses to tell me which one. It just says “Keys.None”
Because of the same reason checking if Keys.OemTilde or Keys.D6 or anything else doesn’t solve this problem, because accoding to MonoGame ^ (and all the other mentioned keys) are all the same “Keys.None”.
Out of curiosity I tried if MLEM solves this problem, but their InputHandler behaves the same as they seem to rely on MonoGame’s KeyboardState
//edit: I just tested it in Stardew Valley. Even there this bug exists.
You cannot use ö ä ü # ´ ^ as any sort of hotkey because it’s detected as “none”.
… with a german keyboard layout of course.
I mean it isn’t the biggest issue obviously, I just wonder if other keyboard layouts in different languages are affected even worse (russian, greek?)
I may be wrong, but afaik MG does map the keys manually in code somewhere - so you might be able to adapt the MG source at this point to get the keys you desire - at least that may be the reason why you get “Keys.None” for those. I think it was just a big switch block processing the systems messages or something like that
btw. the problem with using tilde for console exists in a lot of games actually
They are mapped in KeyboardUtil.SDL.cs
They are manually creating a Dictionary and adding the keys there.
And I am not sure why the german keyboard layout has different keycodes (if that’s the right term?) than the US layout, but I can indeed “fix it” by adding those mappings:
Now I just have to think about how I’m gonna handle this going forward
I am assuming if I suggest this dirty fix as a PR it won’t get merged, and I am not sure if I have the skills yet to create a clean solution for this.
Oh well, worst case I will have to use my own MonoGame fork.
Thank you for your suggestions!
I can definitely use these keys now and potentially manually fix this for several different keyboard layouts
I’m guessing you’re getting those Keys values based on the corresponding Key located at the same position on a US keyboard? This documentation is showing different values. For example the German ß key is Keys.Oem4 even though it’s located in the same spot as the Keys.OemMinus key of a US keyboard.
I see, yes you are right. Oem4 would be the correct one.
However, this does not exist by default in the Keys enum that MonoGame uses and while I obviously could add it, doing that for every (major) layout seems like a lot of work.
So what I tried instead is rewriting the KeyboardUtil dictionary to map the scancodes instead and use the scancode in SDLGamePlatform.SdlRunLoop().
I mapped them all to the Keys enum that fits the US keyboard layout.
So even if I click ^ now on my german keyboard, it will get detected as OemTilde. While this is not the cleanest solution, I think it is somewhere near the golden medium / happy mean for me personally.
I now know that whatever key I map, I just need to use the US key to get the “same” mapping for all keyboard layouts. So if I map walking to WASD then using ZQSD on an AZERTY keyboard will work just fine. I think I might actually submit a PR request for this and see what happens.
It certainly shouldn’t be any worse than the current solution where some keys are straight up not supported on other layouts and it also shouldn’t have any side effect to the default US layout