Add the Globe key check

This commit is contained in:
1024jp 2023-12-02 12:25:22 +09:00
parent de726ed8f1
commit 7142dc1f4c
2 changed files with 22 additions and 4 deletions

View File

@ -2,6 +2,15 @@
Change Log
==========================
4.7.0 (unreleased)
--------------------------
### Improvements
- [rc] Display the Globe symbol instead of “fn” for shortcuts in the Quick Action bar if the user keyboard is supposed to have the Globe key (thanks to Katsumi Kishikawa!).
4.7.0-rc (615)
--------------------------

View File

@ -26,6 +26,7 @@
import Foundation
import AppKit.NSEvent
import IOKit
/// Modifier keys for keyboard shortcut.
///
@ -41,10 +42,6 @@ private enum ModifierKey: CaseIterable {
static let validCases: [Self] = Array(Self.allCases[0..<4])
/// It seems there is no easy way to detect the Globe key without private APIs... (2023-12 on macOS 14)
private static let supportsGlobeKey = false
/// NSEvent.ModifierFlags representation.
var mask: NSEvent.ModifierFlags {
@ -95,6 +92,18 @@ private enum ModifierKey: CaseIterable {
case .function: preconditionFailure("Fn/Globe key cannot be used for custom shortcuts.")
}
}
/// Return `true` if the user keyboard is supposed to have the Globe key.
private static let supportsGlobeKey = {
let entry = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleHIDKeyboardEventDriverV2"))
defer { IOObjectRelease(entry) }
guard let property = IORegistryEntryCreateCFProperty(entry, "SupportsGlobeKey" as CFString, kCFAllocatorDefault, 0)?.takeRetainedValue() else { return false }
return (property as? Int) == 1
}()
}