102*_*4jp 5 macos cocoa appkit swift swiftui
最近的 Apple 产品的键盘上有 Globe (\xef\xb8\x8e) 键。在 AppKit 级别,它实际上只是一个 Fn 键,其行为与NSEvent.ModifierFlags.function. 但是有什么方法可以知道用户当前使用的键盘是有 Globe 键还是只有 Fn 键呢?
似乎系统以某种方式知道它,因为菜单中的快捷键显示根据键盘而变化。仅当键盘实际有 Globe 键时才会显示 Globe 符号。否则,显示“fn”。
\n\n但是,到目前为止,我还没有找到一种在 AppKit/SwiftUI 世界中以编程方式检测它的方法。我想在我自己的视图中实现显示这些菜单命令的键盘快捷键。
\nI /O 注册表似乎包含有关 Globe 键是否存在\xe3\x80\x80("SupportsGlobeKey" = Yes或No)的信息。
在我的环境(MacBook Pro 2023)中,ioreg -rln AppleHIDKeyboardEventDriverV2给出以下结果。\n(我没有台式机,因此无法验证是否存在 Globe 键)。
$ ioreg -rln AppleHIDKeyboardEventDriverV2\n+-o AppleHIDKeyboardEventDriverV2 <class AppleHIDKeyboardEventDriverV2, id 0x100000ba5, registered, matched, active, busy 0 (0 ms), retain 10>\n | {\n | "LocationID" = 49\n | "IOPersonalityPublisher" = "com.apple.driver.AppleTopCaseDriverV2"\n | "Keyboard" = {"Elements"=({"VariableSize"=0,"UnitExponent"=0,"IsRelative"=No,"UsagePage"=7,"Max"=1,"IsArray"=No,"Type"=2,"Size"=1,"Min"=0,"Flags"=134217730,"ReportID"=1,"Usage"=224,"ReportCount"=1,"Unit"=0,"Ha$\n | "IOMatchCategory" = "IODefaultMatchCategory"\n | "CapsLockLanguageSwitch" = No\n | "HIDServiceSupport" = Yes\n*snip*\n | "KeyboardEnabled" = Yes\n | "PrimaryUsagePage" = 1\n | "CFBundleIdentifierKernel" = "com.apple.driver.AppleHIDKeyboard"\n | "SupportsGlobeKey" = Yes\n | "SensorProperties" = {}\n | "ProductID" = 0\n*snip*\nRun Code Online (Sandbox Code Playgroud)\n要以编程方式获取 I/O 注册表信息,请使用IOKit.
例如,要获取地球键是否存在,请使用以下代码。
\n$ ioreg -rln AppleHIDKeyboardEventDriverV2\n+-o AppleHIDKeyboardEventDriverV2 <class AppleHIDKeyboardEventDriverV2, id 0x100000ba5, registered, matched, active, busy 0 (0 ms), retain 10>\n | {\n | "LocationID" = 49\n | "IOPersonalityPublisher" = "com.apple.driver.AppleTopCaseDriverV2"\n | "Keyboard" = {"Elements"=({"VariableSize"=0,"UnitExponent"=0,"IsRelative"=No,"UsagePage"=7,"Max"=1,"IsArray"=No,"Type"=2,"Size"=1,"Min"=0,"Flags"=134217730,"ReportID"=1,"Usage"=224,"ReportCount"=1,"Unit"=0,"Ha$\n | "IOMatchCategory" = "IODefaultMatchCategory"\n | "CapsLockLanguageSwitch" = No\n | "HIDServiceSupport" = Yes\n*snip*\n | "KeyboardEnabled" = Yes\n | "PrimaryUsagePage" = 1\n | "CFBundleIdentifierKernel" = "com.apple.driver.AppleHIDKeyboard"\n | "SupportsGlobeKey" = Yes\n | "SensorProperties" = {}\n | "ProductID" = 0\n*snip*\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
233 次 |
| 最近记录: |