28 lines
1.5 KiB
Swift
28 lines
1.5 KiB
Swift
import CoreGraphics
|
|
|
|
/// A modifier key that can be held to dictate. Left/right keys share a flag, so the key code decides.
|
|
public struct HotkeyBinding: Hashable, Sendable, Identifiable {
|
|
public let id: String
|
|
public let displayName: String
|
|
public let keyCode: Int
|
|
public let flagRawValue: UInt64
|
|
|
|
public var flag: CGEventFlags { CGEventFlags(rawValue: flagRawValue) }
|
|
|
|
public static let fn = HotkeyBinding(
|
|
id: "fn", displayName: "Fn", keyCode: 63, flagRawValue: CGEventFlags.maskSecondaryFn.rawValue)
|
|
public static let rightOption = HotkeyBinding(
|
|
id: "rightOption", displayName: "Rechter Option", keyCode: 61, flagRawValue: CGEventFlags.maskAlternate.rawValue)
|
|
public static let rightCommand = HotkeyBinding(
|
|
id: "rightCommand", displayName: "Rechter Command", keyCode: 54, flagRawValue: CGEventFlags.maskCommand.rawValue)
|
|
public static let rightControl = HotkeyBinding(
|
|
id: "rightControl", displayName: "Rechter Control", keyCode: 62, flagRawValue: CGEventFlags.maskControl.rawValue)
|
|
public static let leftControl = HotkeyBinding(
|
|
id: "leftControl", displayName: "Linker Control", keyCode: 59, flagRawValue: CGEventFlags.maskControl.rawValue)
|
|
|
|
public static let allowed: [HotkeyBinding] = [.fn, .rightOption, .rightCommand, .rightControl, .leftControl]
|
|
|
|
public static func binding(id: String) -> HotkeyBinding? { allowed.first { $0.id == id } }
|
|
public static func binding(keyCode: Int) -> HotkeyBinding? { allowed.first { $0.keyCode == keyCode } }
|
|
}
|