macOS 上用于记录快捷键的最佳控件
此框架包含
SRRecorderControl
用于渲染和捕获用户输入SRRecorderControlStyle
用于自定义样式SRShortcut
代表快捷键模型SRGlobalShortcutMonitor
通过注册全局热键将快捷键转换为动作SRAXGlobalShortcutMonitor
通过辅助功能处理任何类型的键盘事件SRLocalShortcutMonitor
用于在响应链和 NSEvent
监视器中手动处理SRShortcutController
用于流畅的 Cocoa Bindings 和无缝的 Interface Builder 集成SRShortcutValidator
用于检查快捷键相对于 Cocoa 键等价物和全局热键的有效性NSValueTransformer
和 NSFormatter
子类用于自定义修改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>
.package(url: "git://github.com/Kentzo/ShortcutRecorder.git", from: "3.4.0")
pod 'ShortcutRecorder', '~> 3.4.0'
github "Kentzo/ShortcutRecorder" ~> 3.4.0
预构建的框架可通过 GitHub 发布版本获取。
git submodule add git://github.com/Kentzo/ShortcutRecorder.git
然后将其拖放到您项目的 Xcode 工作区中。
还有其他问题?创建一个 issue。
我们提供付费支持,包括自定义修改、集成方面的帮助以及有关 Apple 平台开发的通用建议。