macOS:是否有可能检测到"fn"何时出现?在Mac键盘上按下键? [英] macOS: Is it possible to detect when the "fn" key is pressed on a mac keyboard?

查看:284
本文介绍了macOS:是否有可能检测到"fn"何时出现?在Mac键盘上按下键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,是否有可能检测何时在Mac键盘上按下"fn"键,无论是单独使用还是与其他键组合使用.有没有办法做到这一点?我愿意使用任何一种方法,如有必要,包括未公开的Apple API.

解决方案

按下Fn键时,所有键盘NSEvent的.modifierFlags中都将具有NSEventModifierFlagFunction(在Swift中为NSEvent.ModifierFlags.function).

要单独测试Fn而不是与其他键盘事件结合使用,似乎在按下或释放Fn键时,会发送NSSF类型为NSFlagsChanged(在Swift中为NSEvent.EventType.flagsChanged)的NSEvent. /p>

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.

解决方案

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

这篇关于macOS:是否有可能检测到"fn"何时出现?在Mac键盘上按下键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆