Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DebugConsole to work with all keyboards. #640

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Epicguru
Copy link
Contributor

@Epicguru Epicguru commented Nov 5, 2020

The DebugConsole used a really bad switch statement to detect key input.
It was hard-coded to work with a standard US keyboard layout. If using another keyboard layout, it would not work (added wrong character).
It also didn't allow for smooth typing (holding down a key would only type 1 character).

I've changed it to use Core.Window.TextInput event to get the character that the user actually typed. This makes it work with all keyboard layouts, and whatever keyboard profile the user currently has active.

As far I'm aware, this should work for all supported (desktop) platforms. All console functionality remains intact.

Note, that when typing a character that does not exist in the BitmapFont, the font will throw an exception. This is another bug, for another pull request...

@prime31
Copy link
Owner

prime31 commented Nov 5, 2020

Unfortunately, Window.TextInput wasnt in the XNA spec so it doesnt exist in FNA. I'll see if I can add a divergent path behind a compiler flag to use FNA's TextInputEXT instead when using FNA.

@Epicguru
Copy link
Contributor Author

Epicguru commented Nov 5, 2020

Ah, I forgot about FNA not having all Monogame features. I'll pull FNA and see if I can work something out.

@Epicguru
Copy link
Contributor Author

Epicguru commented Nov 5, 2020

I've changed it so that it has old behaviour on FNA, and improved behaviour with monogame, using conditional compilation tags (#if FNA).

It's pretty messy, but it does work. Ideally I want to find a way to get correct key input on FNA, so I'll do some more investigating. I understand if you don't want to merge a half-solution that only works on Monogame and adds a lot of mess.

@Epicguru
Copy link
Contributor Author

Epicguru commented Nov 6, 2020

Ok. The code is even messier, but it now works fully on both monogame and FNA. Keys typed now match user keyboard layout, and you can hold keys to keep typing, including tab and backspace. Functionality has not changed.

The bug relating to BitmapFont crashing when a character is missing still needs fixing. I will open another PR if you want.

If you don't want to merge this because of the messy code, that's fine. I mostly made this for myself.

@prime31
Copy link
Owner

prime31 commented Nov 6, 2020

I'll see if i can do some cleansing in there and unifiy the FNA/MG code paths somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants