CC BY 4.0 macOS 10.11 Mac App Store Approved

CocoaPods Compatible Carthage Compatible SPM Compatible

Coverage Build Status

ShortcutRecorder

Showcase

macOS 上用于记录快捷键的最佳控件

包含内容

此框架包含

Swift 示例

import ShortcutRecorder

let defaults = NSUserDefaultsController.shared
let keyPath = "values.shortcut"
let options = [NSBindingOption.valueTransformerName: .keyedUnarchiveFromDataTransformerName]

let beepAction = ShortcutAction(keyPath: keyPath, of: defaults) { _ in
    NSSound.beep()
    return true
}
GlobalShortcutMonitor.shared.addAction(beepAction, forKeyEvent: .down)

let recorder = RecorderControl()
recorder.bind(.value, to: defaults, withKeyPath: keyPath, options: options)

recorder.objectValue = Shortcut(keyEquivalent: "⇧⌘A")

Objective-C 示例

#import <ShortcutRecorder/ShortcutRecorder.h>

NSUserDefaultsController *defaults = NSUserDefaultsController.sharedUserDefaultsController;
NSString *keyPath = @"values.shortcut";
NSDictionary *options = @{NSValueTransformerNameBindingOption: NSKeyedUnarchiveFromDataTransformerName};

SRShortcutAction *beepAction = [SRShortcutAction shortcutActionWithKeyPath:keyPath
                                                                  ofObject:defaults
                                                             actionHandler:^BOOL(SRShortcutAction *anAction) {
    NSBeep();
    return YES;
}];
[[SRGlobalShortcutMonitor sharedMonitor] addAction:beepAction forKeyEvent:SRKeyEventTypeDown];

SRRecorderControl *recorder = [SRRecorderControl new];
[recorder bind:NSValueBinding toObject:defaults withKeyPath:keyPath options:options];

recorder.objectValue = [SRShortcut shortcutWithKeyEquivalent:@"⇧⌘A"];

集成

该框架支持 模块映射,无需显式链接:只需 import ShortcutRecorder / #import <ShortcutRecorder/ShortcutRecorder.h>

Swift Package Manager

.package(url: "git://github.com/Kentzo/ShortcutRecorder.git", from: "3.4.0")

CocoaPods

pod 'ShortcutRecorder', '~> 3.4.0'

Carthage

github "Kentzo/ShortcutRecorder" ~> 3.4.0

预构建的框架可通过 GitHub 发布版本获取。

Git Submodule

git submodule add git://github.com/Kentzo/ShortcutRecorder.git

然后将其拖放到您项目的 Xcode 工作区中。

下一步

问题

还有其他问题?创建一个 issue

付费支持

我们提供付费支持,包括自定义修改、集成方面的帮助以及有关 Apple 平台开发的通用建议。