libobs: Always explicitly check modifiers in macOS hotkey event handler #11100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Changes the macOS hotkey system event handler to always explicitly register the state of the modifier keys, regardless of the event type that was received.
Motivation and Context
It turns out that applications will not always receive a "flags changed" NSEvent from the system when a modifier key status is either pressed or let go of. These events seem particularly likely to be eaten by the system or other applications if the modifier is released, and that action results in the application losing focus (Command + Tab, for example), though it can also happen under some other circumstances. This means that OBS can often spuriously think that a modifier key is held when it is not, or, more rarely, that a modifier is not held when it is. This will in turn cause OBS's hotkey system to fail to properly register hotkey events.
Explicitly checking and registering the state of these modifier keys on every monitored keypress is slightly less efficient, but removes all reliance on these events, and means that OBS will always know accurately what modifier keys are held.
Should resolve #4126, #9023, possibly others.
How Has This Been Tested?
Tested on Apple Silicon, macOS 15. Verified that both one-shot and "push-to" hotkeys now work much more reliably with OBS focused and unfocused, particularly when tabbing into and out of OBS.
Other
I thought about possibly basing this off of #9583, in order to take advantage of the better TCC granularity of
CGEventTap
at the same time as fixing this bug. If maintainers think that that is a good idea, would be happy to rewrite this from there, or we could maybe even just merge this fix on top of that PR instead (@gxalpha @PatTheMav thoughts?)Types of changes
Checklist: