Structure
KeyboardShortcuts.Shortcut
public struct Shortcut: Hashable, Codable
A keyboard shortcut.
Relationships
Member Of
KeyboardShortcuts
Global keyboard shortcuts for your macOS app.
Conforms To
Codable
CustomStringConvertible
Hashable
Initializers
init(carbonKeyCode:carbonModifiers:)
public init(carbonKeyCode: Int, carbonModifiers: Int = 0)
Initialize from a key code number and modifier code.
init(_:modifiers:)
public init(_ key: Key, modifiers: NSEvent.ModifierFlags = [])
Initialize from a strongly-typed key and modifiers.
init?(event:)
public init?(event: NSEvent)
Initialize from a key event.
init?(name:)
public init?(name: Name)
Initialize from a keyboard shortcut stored by Recorder
or RecorderCocoa
.
Properties
carbonKeyCode
let carbonKeyCode: Int
carbonModifiers
let carbonModifiers: Int
key
var key: Key?
modifiers
var modifiers: NSEvent.ModifierFlags
system
var system: [Self]
System-defined keyboard shortcuts.
isTakenBySystem
var isTakenBySystem: Bool
Check whether the keyboard shortcut is already taken by the system.
keyEquivalent
var keyEquivalent: String
This can be used to show the keyboard shortcut in a NSMenuItem
by assigning it to NSMenuItem#keyEquivalent
.
description
var description: String
The string representation of the keyboard shortcut.
print(Shortcut(.a, modifiers: [.command]))
//=> "⌘A"
Methods
normalizeModifiers(_:)
private static func normalizeModifiers(_ carbonModifiers: Int) -> Int
Carbon modifiers are not always stored as the same number.
For example, the system has ⌃F2
stored with the modifiers number 135168
, but if you press the keyboard shortcut, you get 4096
.
keyToCharacter()
fileprivate func keyToCharacter() -> String?