KeyboardShortcuts icon indicating copy to clipboard operation
KeyboardShortcuts copied to clipboard

curious about why the KeyboardShortcut is caught within a VNC session on the remote computer rather than on the local one

Open godbout opened this issue 11 months ago • 2 comments

trying to wrap my head around this. just out of curiosity. i have an app that uses the KeyboardShortcuts package. my app is both on my local and my remote computer. if i'm on Screen Sharing, pressing my KeyboardShortcut will activate my app within the Screen Sharing environment, on the remote computer, rather than on a local one. no right or wrong here, but curious about why is this happening. is this done on purpose? KeyboardShortcuts isn't using an event tap, so there's not that concept of where in the event stream the tap is placed, which could explain the behavior depending on where the tap is. i don't have much knowledge about the Carbon API etc. so there's definitely something basic i'm missing. curious curious curious...

godbout avatar Jan 03 '25 17:01 godbout

Keys are generally captured when in VNC.

sindresorhus avatar Jan 03 '25 21:01 sindresorhus

Keys are generally captured when in VNC.

good one hahahhaahhahahahahahah alright i deserve it hahahahhahahhhahahhahhaha

ok, so lemme try to give a bit more details:

  1. i build three apps: kindaVim, Wooshy and Scrolla (naming them so it's easier to remember, and also for self-promotion of course)
  2. Wooshy and Scrolla are using your masterpiece KeyboardShortcuts package. kindaVim doesn't and uses an event tap instead because it needs to grab every single key in order to generate Vim motions as a result
  3. when on Screen Sharing, hitting the keyboard shortcuts for Wooshy and Scrolla makes Wooshy and Scrolla open on the remote computer. when hitting my own keyboard shortcut system for kindaVim (like escape, or a sequence of keys) kindaVim reacts on the local computer

so what's happening here is that kindaVim's event tap grab the keystrokes before Screen Sharing does. for Wooshy and Scrolla, Screen Sharing grabs the keystrokes before they (hence before KeyboardShortcuts) do. obviously, there is a priority in which system (event tap, KS hotkeys)/apps grab the keystrokes first.

now why i'm asking you/here is because:

  1. i'm dealing with an issue with iTerm. when i use iTerm's hotkey iTerm opens on the local computer instead of the remote one. i'm dealing with iTerm's developer George, who says the hotkeys are handled through Carbon keys blah blah blah, the same way KeyboardShortcuts does. i haven't dig/dug yet into iTerm's source, but George being the maintainer of iTerm for the past like, 15 years?, i kinda believe he knows what he's saying
  2. as we all know you are a Wizard. so i thought that maybe you DO have some knowledge about how keystrokes grabbing priorities work when dealing with the old Carbon keys APIs. i thought that maybe you'd have something like "yeah KeyboardShortcuts grabs keys very late in the old Carbon keys APIs event process so other apps like Screen Sharing will catch them first and here's a link to the source where the grabbing keys priority is defined: github.com/blahblahblah"

hope that makes sense! i'm just a big fan of knowledge i can't help it hope i'm not abusing your time xoxo.

godbout avatar Jan 04 '25 06:01 godbout

macOS routes keys through the WindowServer pipeline where event taps run before Carbon hotkeys. Screen Sharing (in Control mode) installs a session-level tap that forwards keys to the remote Mac and can consume them locally, so a Carbon RegisterEventHotKey never fires on the local machine. Your event-tap app wins locally because taps run earlier and can swallow events. iTerm’s special hotkeys work locally because it also uses an event tap (with Accessibility/Input Monitoring). Changing this library to use taps would require TCC permissions, which is out of scope.

sindresorhus avatar Sep 17 '25 07:09 sindresorhus

excellent. thank you. wasn't looking for things to be changed, was just curious about the whys and whats. perfect.

godbout avatar Sep 17 '25 13:09 godbout