I want to detect when the user presses the fn key and do some tasks. I tried the below but it doesn't work:
if event.keyCode == kVK_Function {
print("fn key pressed")
}
I have similar code for other keys like left bracket, right bracket, slash, alphabets, and numbers. For these keys, the code, shown above, works fine but it doesn't work for fn key. I think this is handled differently.
You need to check the NSEvent
's modifierFlags
:
if event.modifierFlags.contains(.function) {
print("fn key pressed")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With