I'm curious if it's possible to detect when the "fn" key is pressed on a mac keyboard, either when it's used on its own or when used in combination with another key. Is there a way to do that? I'm open to using any sort of method, including undocumented Apple APIs if necessary.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
All keyboard NSEvents will have NSEventModifierFlagFunction (NSEvent.ModifierFlags.function in Swift) in their .modifierFlags when the Fn key is down.
To test for Fn on its own rather than in combination with some other keyboard event, it appears that when the Fn key is depressed or released, an NSEvent gets sent with type NSFlagsChanged (NSEvent.EventType.flagsChanged in Swift).