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

Exclamation mark does not work with some keyboard layouts #308

Closed
najlkin opened this issue Aug 14, 2024 · 4 comments
Closed

Exclamation mark does not work with some keyboard layouts #308

najlkin opened this issue Aug 14, 2024 · 4 comments
Assignees
Labels

Comments

@najlkin
Copy link
Contributor

najlkin commented Aug 14, 2024

Exclamation mark for changing the texture type does not work with some keyboard layouts (like Czech).

Here is the output from tracking of key presses with Czech layout:

Event: SDL_KEYDOWN sym=1073742053 mod=4098
Event: SDL_KEYDOWN sym=167 mod=4098
Event: SDL_TEXTINPUT text[0..3]=33 0 0 0 (as codes 0-255)
Event: SDL_KEYUP sym=167 mod=4098
Event: SDL_KEYUP sym=1073742053 mod=4096

and for reference English layout (which works):

Event: SDL_KEYDOWN sym=1073742049 mod=4097
Event: SDL_KEYDOWN sym=49 mod=4097
Event: SDL_TEXTINPUT text[0..3]=33 0 0 0 (as codes 0-255)
Event: SDL_KEYUP sym=49 mod=4097
Event: SDL_KEYUP sym=1073742049 mod=4096

❓ This probably comes from #294

@najlkin najlkin added the bug label Aug 14, 2024
@najlkin najlkin self-assigned this Aug 14, 2024
@najlkin najlkin mentioned this issue Aug 14, 2024
12 tasks
@najlkin
Copy link
Contributor Author

najlkin commented Aug 14, 2024

This is wrong

if ((ks.sym >= 32 && ks.sym < 127) &&
but I do not know how to fix it. The thing is the key (167) is out of the range, but with Shift/Caps Lock it is translated to the range (33).

@najlkin
Copy link
Contributor Author

najlkin commented Aug 14, 2024

Translation by SDL_GetScancodeName() would work for me, as it at least returns the key with English layout, which is apostrophe, but it is not universal 🤔

@najlkin
Copy link
Contributor Author

najlkin commented Aug 14, 2024

Actually, it should be fine, because US keyboard matches ASCII table 😉

@najlkin
Copy link
Contributor Author

najlkin commented Aug 14, 2024

This would be the fix working for me:

const char *scan_name = SDL_GetScancodeName(ks.scancode);
if ((scan_name[0] >= 32 && scan_name[0] < 127) && scan_name[1] == '\0'
    && (ks.mod & (KMOD_CTRL | KMOD_ALT | KMOD_GUI)) == 0)

Update: This possible fix is in #309 . Please test it!

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

No branches or pull requests

2 participants