soffes / HotKey

Simple global shortcuts in macOS
MIT License
921 stars 82 forks source link

Unable to capture fn key #31

Open torywalker opened 3 years ago

torywalker commented 3 years ago

Setup

macOS: 11.0.1 HotKey: 0.1.3 Deployment Target: 10.15 XCode Version: 12.3

Issue

I seem to be unable to capture the fn key with HotKey when looking at the modifierFlags.

let carbonKey = UInt32(event.keyCode)
let carbonFlags = event.modifierFlags.carbonFlags

self.hotKey = HotKey(keyCombo: KeyCombo(
    carbonKeyCode: carbonKey,
    carbonModifiers: carbonFlags
))

I also tried passing the modifierFlags directly:

let carbonKey = UInt32(event.keyCode)

self.hotKey = HotKey(keyCombo: KeyCombo(
    key: Key(carbonKeyCode: carbonKey)!,
    modifiers: event.modifierFlags
))

When recording a shortcut with the fn pressed, it seems to omit fn from what is stored. Executing the recorded shortcut with fn pressed also does not activate the shortcut (it does work when omitting fn key).

When describing the stored shortcut, the fn key, it is absent:

self.hotKey?.keyCombo.description

However, performing the following check prior to storage indicates that the fn key is indeed present

if (event.modifierFlags.contains(.function)) {
    // this evaluates to true
}

Is there anything I'm missing? Is this unsupported?

tybug commented 3 years ago

Same issue here. A workaround would be appreciated if anyone finds one.

luser commented 3 years ago

I tried using this to capture Fn+Space (I bought a new keyboard that has a "Microphone" key that sends that combo.) and similarly wasn't able to:

let hotKey = HotKey(key: .space, modifiers: [.function])