KeyboardShortcuts Documentation Beta

Structure Keyboard​Shortcuts.​Shortcut

public struct Shortcut: Hashable, Codable

A keyboard shortcut.

KeyboardShortcuts.Shortcut KeyboardShortcuts.Shortcut Hashable Hashable KeyboardShortcuts.Shortcut->Hashable CustomStringConvertible CustomStringConvertible KeyboardShortcuts.Shortcut->CustomStringConvertible Codable Codable KeyboardShortcuts.Shortcut->Codable

Member Of

KeyboardShortcuts

Global keyboard shortcuts for your macOS app.

Conforms To

Codable
CustomStringConvertible
Hashable

Initializers

init(carbon​Key​Code:​carbon​Modifiers:​)

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

carbon​Key​Code

let carbonKeyCode: Int

carbon​Modifiers

let carbonModifiers: Int

key

var key: Key?

modifiers

var modifiers: NSEvent.ModifierFlags

system

var system: [Self]

System-defined keyboard shortcuts.

is​Taken​BySystem

var isTakenBySystem: Bool

Check whether the keyboard shortcut is already taken by the system.

taken​ByMain​Menu

var takenByMainMenu: NSMenuItem?

Returns a menu item in the app's main menu that has a matching key equivalent and modifier.

key​Equivalent

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

normalize​Modifiers(_:​)

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.

menu​Item​With​Matching​Shortcut(in:​)

func menuItemWithMatchingShortcut(in menu: NSMenu) -> NSMenuItem?

Recursively finds a menu item in the given menu that has a matching key equivalent and modifier.

key​ToCharacter()

fileprivate func keyToCharacter() -> String?