macOS: Is it possible to detect when the “fn” key is pressed on a mac keyboard?

为君一笑 提交于 2019-12-11 08:49:37

问题


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).



来源:https://stackoverflow.com/questions/45516031/macos-is-it-possible-to-detect-when-the-fn-key-is-pressed-on-a-mac-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!