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

macOS modifiers become sticky when released simultaneously #10934

Open
williamhCode opened this issue Sep 24, 2024 · 5 comments
Open

macOS modifiers become sticky when released simultaneously #10934

williamhCode opened this issue Sep 24, 2024 · 5 comments
Assignees
Labels
waiting Waiting on user response
Milestone

Comments

@williamhCode
Copy link

williamhCode commented Sep 24, 2024

Hello, I updated to the SDL3 main branch a few weeks ago (and recently also), and this issue appeared.

Basically, when two modifiers are released simultaneously, the modifiers become sticky.

This becomes problematic when using macros on mouses, when keystrokes are invoked programmatically and thus very precisely. I have a test macro that presses alt (it pressed both left and right), and the alt modifier stays even after I released it. Only when I press another modifier does it get reset. My guess is there might be a race condition when trying to set the mod state simultaneously?

sdlbug.mov

Here im invoking the macro that presses LALT + RALT, then pressing jkjk. Only after i press ctrl, do the mod state reset.

@slouken slouken added this to the 3.2.0 milestone Sep 25, 2024
@slouken slouken self-assigned this Oct 6, 2024
@slouken
Copy link
Collaborator

slouken commented Dec 23, 2024

Can you provide instructions for setting up your macro? I couldn't reproduce this just by hitting the keys myself.

@slouken slouken added the waiting Waiting on user response label Dec 23, 2024
@williamhCode
Copy link
Author

I use a logitech mouse and logitech G HUB to setup the macro which is just recording a single ALT. Recording any ALT just triggers both ALTs when played back with my setup.

@slouken
Copy link
Collaborator

slouken commented Dec 26, 2024

I tried installing G HUB, but it says my Logitech mouse is inactive. Can you debug Cocoa_HandleKeyEvent() and see what's going on there?

@williamhCode
Copy link
Author

williamhCode commented Dec 29, 2024

Hi, I tried using a debugger and stepping through, but the bug doesn't occur when it gets paused. So I printed the modflags near the end of Cocoa_HandleKeyEvent like this. I also printed event.mod from SDL_Event.

    case NSEventTypeFlagsChanged: {
        // see if the new modifierFlags mean any existing keys should be pressed/released...
        const unsigned int modflags = (unsigned int)[event modifierFlags];
        printf("modflags: %x\n", modflags);
...

Envoking the macro gives me

modflags: 80020
INFO: down, mods: LAlt 
modflags: 80000
INFO: down, mods: LAlt 
INFO: down, mods: LAlt RAlt 

If I try pressing it manually (left alt pressed first and released first) it gives this

modflags: 80120
INFO: down, mods: LAlt 
modflags: 80160
INFO: down, mods: LAlt 
INFO: down, mods: LAlt RAlt 
modflags: 80140
INFO: up, mods: RAlt 
INFO: down, mods: RAlt 
modflags: 100
INFO: up, mods: 

The macro doesn't trigger any release event which seems like is the problem.

From my understanding 0x80000 means either LAlt and RAlt are pressed, but it's missing the 0x20 and 0x40 bits that are supposed to represent specifically if LAlt or RAlt is being pressed. Perhaps a special case or an apple bug?

@slouken
Copy link
Collaborator

slouken commented Dec 29, 2024

Possibly an Apple bug, or a bug in how G HUB is simulating key presses. I'm going to bump this out of the milestone, but feel free to continue your investigation here.

@slouken slouken modified the milestones: 3.2.0, 3.x Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting Waiting on user response
Projects
None yet
Development

No branches or pull requests

2 participants