kasper / phoenix

A lightweight macOS window and app manager scriptable with JavaScript
https://kasper.github.io/phoenix/
Other
4.36k stars 128 forks source link

Fn modifier? #277

Closed rcarmo closed 2 years ago

rcarmo commented 3 years ago

It would be nice to have Fn (kCGEventFlagMaskSecondaryFn) as a modifier key as well (I'm running out of modifiers).

kasper commented 3 years ago

Unfortunately, I’m pretty sure the Carbon events used for hot keys did not support “fn” as a modifier. The event referred is for the regular key events.

mafredri commented 3 years ago

It looks like the Fn key is assignable these days in the macOS Preferences but only basic re-mapping like other modifiers or No Action. Ideally No Action would allow for control in Phoenix but it's probably not possible :(.

@rcarmo As a work-around, you could try using Karabiner-Elements to map fn to something like f19 (possibly also set No Action for it in macOS preferences). However, f19 is a key, not a modifier, so there are two options:

  1. You can, in Karabiner, map fn/f19 to be multiple modifiers (e.g. command+option+control) and assign your Phoenix events to the modifier combos, or...
  2. You can emulate a modifier inside Phoenix

Re 2., I've done this in the past and it works OK, there is and edge-cases / timing issue though where the modifiers will be active for a bit longer than ideal. This is because the timeouts need to be ~matched to key-repeat events (IIRC there's no observable key released event which would eliminate the timing issue). To improve this, the macOS key-repeat / duration before repeat can be decreased to make it work better. What you'd do is essentially:

  1. F19 pressed, enable F19 key bindings (keys without modifiers), set timeout for after initial key repeat
  2. F19 key-repeat event received, keep active, reset timeout to after key-repeat
  3. Timeout hit, disable bindings

https://github.com/mafredri/phoenix-config/blob/b8dad65c6ddcb197706f2545bdd259d82b2af11b/src/key.ts

kasper commented 3 years ago

@mafredri Thanks for giving some options! 🙂