I/O注册表似乎有关于是否存在全球键的信息("SupportsGlobeKey" = Yes
或No
)。
在我的环境中(MacBook Pro 2023),ioreg -rln AppleHIDKeyboardEventDriverV2
给出了以下结果。
(我没有台式机,所以无法验证是否缺少全球键)。
$ ioreg -rln AppleHIDKeyboardEventDriverV2
+-o AppleHIDKeyboardEventDriverV2 <class AppleHIDKeyboardEventDriverV2, id 0x100000ba5, registered, matched, active, busy 0 (0 ms), retain 10>
| {
| "LocationID" = 49
| "IOPersonalityPublisher" = "com.apple.driver.AppleTopCaseDriverV2"
| "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$
| "IOMatchCategory" = "IODefaultMatchCategory"
| "CapsLockLanguageSwitch" = No
| "HIDServiceSupport" = Yes
*snip*
| "KeyboardEnabled" = Yes
| "PrimaryUsagePage" = 1
| "CFBundleIdentifierKernel" = "com.apple.driver.AppleHIDKeyboard"
| "SupportsGlobeKey" = Yes
| "SensorProperties" = {}
| "ProductID" = 0
*snip*
import IOKit
let entry = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleHIDKeyboardEventDriverV2"))
if let property = IORegistryEntryCreateCFProperty(entry, "SupportsGlobeKey" as CFString, kCFAllocatorDefault, 0)?.takeRetainedValue() {
print(property) // => 1
}
IOObjectRelease(entry)
ApplicationServices.HIServices
中的私有API来检测它的方法。HIS_XPC_GetGlobeKeyAvailability();