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

SDL_GetModState does not track Caps lock properly #1974

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

SDL_GetModState does not track Caps lock properly #1974

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.3
Reported for operating system, platform: Windows 7, x86_64

Comments on the original bug report:

On 2015-09-17 17:55:41 +0000, Kutta Srinivasan wrote:

When launching our SDL app, if the user has CAPS LOCK on (i.e. if the OS and their hardware keyboard think that caps lock is on and generate capital letters as text input), SDL_GetModState will return 0. Toggling CAPS LOCK off will then cause SDL_GetModState to return 8192 (0x2000 - KMOD_CAPS). The same behavior can be observed if you alt-tab out, change the caps lock state, then alt tab back in - SDL_GetModState will return whatever value it was returning before even though you have changed the caps lock state.

If this is not a simple repro for you, I can dig deeper to try and figure out why this is the case. I am assuming it's something as simple as SDL assuming that all key mods are off at the beginning of the app and not actually querying the OS to see if caps lock is currently on, thereby putting SDL out of sync with the OS>

What's interesting about this bug is that SDL_TEXTINPUT will always correctly produce the right case of letter based on the OS/hardware caps lock state. Presumably that is going through some other mechanism which is aware of the correct setting of caps lock and not actually using SDL_GetModState to uppercase letters.

On 2015-09-17 18:25:05 +0000, Philipp Wiesemann wrote:

This is maybe related to bug 2736.

On 2015-09-17 19:49:19 +0000, Kutta Srinivasan wrote:

Yep, sounds like 2736 is the same bug - SDL probably doesn't ask (on any platform) for the current toggle state of the num / caps lock keys on startup or after regaining focus, so it's easy for it to get out of sync.

On 2015-10-31 23:36:02 +0000, Konrad wrote:

Hello

I believe it might be worth to bring this bug up. It's quite frustrating.

On 2015-12-28 00:03:51 +0000, Ryan C. Gordon wrote:

Capslock (numlock, scrolllock) having wrong values at startup is now fixed on Windows by https://hg.libsdl.org/SDL/rev/be3d04927338 ...

https://hg.libsdl.org/SDL/rev/75871b5e0bc6 fixes this on Mac OS X.

Our X11 code seems to handle this correctly, but I don't if that was true when this bug report was opened.

I haven't fixed this state getting out of sync on focus change on Windows (it's possible the Mac-specific code already handles this, though).

--ryan.

On 2015-12-28 00:05:22 +0000, Ryan C. Gordon wrote:

(In reply to Ryan C. Gordon from comment # 4)

Our X11 code seems to handle this correctly, but I don't if that was true
when this bug report was opened.

This was fixed for X11 in https://hg.libsdl.org/SDL/rev/7099e2df7b29, which is what Bug # 2736 was dealing with.

--ryan.

On 2015-12-28 18:52:26 +0000, Ryan C. Gordon wrote:

(In reply to Ryan C. Gordon from comment # 4)

Capslock (numlock, scrolllock) having wrong values at startup is now fixed
on Windows by https://hg.libsdl.org/SDL/rev/be3d04927338 ...

https://hg.libsdl.org/SDL/rev/75871b5e0bc6 fixes this on Mac OS X.

Our X11 code seems to handle this correctly, but I don't if that was true
when this bug report was opened.

I haven't fixed this state getting out of sync on focus change on Windows
(it's possible the Mac-specific code already handles this, though).

Okay, as of the latest in revision control:

  • You don't get a key event if caps/numlock is toggled on at startup, but SDL_GetModState(), etc, will properly report them as toggled.

  • You don't get a key event if caps/numlock is toggled while your app is not in the foreground, but SDL will update its internal state when it regains focus, and then SDL_GetModState(), etc, will properly report them as toggled.

  • You will get a key event if these keys are toggled on or off by the user pressing them while your SDL app has focus. You'll get a KEYDOWN followed immediately by a KEYUP, regardless of whether the key is toggling on or off. This is how SDL2 has always worked, so I kept this behavior.

This has been fixed and tested on Windows, Mac OS X, and X11, using the checkkeys program in the test directory. Relevant changesets are:

https://hg.libsdl.org/SDL/rev/75871b5e0bc6
https://hg.libsdl.org/SDL/rev/be3d04927338
https://hg.libsdl.org/SDL/rev/734c90ea9990
https://hg.libsdl.org/SDL/rev/4d8a561cf978
https://hg.libsdl.org/SDL/rev/05770dc93c95
https://hg.libsdl.org/SDL/rev/bb853b9549d0

I'm marking this resolved. Thanks!

--ryan.

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

No branches or pull requests

1 participant