winit icon indicating copy to clipboard operation
winit copied to clipboard

macos: Send CapsLock keyboard events

Open rofferom opened this issue 3 years ago • 5 comments

On macOS, no WindowEvent is sent when CapsLock is pressed.

Actually there is a trick: only the CapsLock state change is sent by macOS, not the state of the keyboard key. The press/release cycle is simulated to fake the presses.

Checklist

  • [ ] Tested on all platforms changed
  • [ ] Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • [ ] Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • [ ] Created or updated an example program if it would help users understand this functionality
  • [ ] Updated feature matrix, if new features were added or implemented

rofferom avatar Oct 18 '22 09:10 rofferom

About how CapsLock should be exposed, I had a look at SDL implementation: it seems that it is a modifier and an event. With the fake Press/Release trick too.

I made some tests with IOKit. With this API it is possible to catch the real key state, but it requires to grants extra permissions to the application in the Preference Pane, which isn't a correct solution.

It seems that it is possible to get events from Quartz, but I don't know the limitations and if it could solve this issue.

rofferom avatar Nov 23 '22 16:11 rofferom

If you're still interested in this, could you rebase or test on the latest master? We were changing the keyboard API, so that's why it was left unnoticed. Now we have a dedicated key for CapsLock and such and generally report the key downstream.

kchibisov avatar Aug 03 '23 16:08 kchibisov

I tried to integrate my commit in the new macOS codebase, but currently it looks like a big hack even if it works. I'm still struggling to understand the update_modifiers() logic.

rofferom avatar Aug 21 '23 14:08 rofferom