使用快捷方式记录器保存/加载键盘快捷键?
我正在 XCode4 中开发 Cocoa/Objective-C 应用程序,它使用 shortcutrecorder 来记录键盘快捷键并将它们保存为默认值。
我正在保存记录器中的 KeyCombo.code
和 KeyCombo.flags
属性,即:
[shortcutRecorder KeyCombo].code
[shortcutRecorder KeyCombo].flags
其中 shortcutRecorder
是 IBOutlet
> 到 SRRecorderControl
。
为了在用户再次打开首选项窗口时恢复保存的键盘快捷键,我从默认值加载 KeyCombo.code
和 KeyCombo.flags
属性,并且需要将它们恢复为`SRRecorderControl.
我正在尝试这样做:
[shortcutRecorder setKeyCombo:[
PTKeyCombo keyComboWithKeyCode:
[shortcutRecorder keyCombo].code
modifiers:[shortcutRecorder cocoaToCarbonFlags:[shortcutRecorder
keyCombo].flags]]];
但这会导致错误:将“id”发送到不兼容类型“KeyCombo”(又名“struct_KeyCombo”)的参数
我认为这可能是因为setKeyCombo
采用 KeyCombo
对象而不是 PTKeyCombo
对象,所以我更改了它:
[shortcutRecorder setKeyCombo:[
KeyCombo keyComboWithKeyCode:
[shortcutRecorder keyCombo].code
modifiers:[shortcutRecorder cocoaToCarbonFlags:[shortcutRecorder
keyCombo].flags]]];
但现在我收到错误: Receiver type 'KeyCombo' (aka 'struct_KeyCombo') 不是 Objective-C 类
我不知道如何创建一个有效的对象来传递给 setKeyCombo
。关于处理这个问题的最佳方法有什么建议吗?
I am working on a Cocoa/Objective-C app in XCode4 that uses shortcutrecorder to record keyboard shortcuts and save them to defaults.
I am saving the KeyCombo.code
and KeyCombo.flags
attributes from the recorder, i.e:
[shortcutRecorder KeyCombo].code
[shortcutRecorder KeyCombo].flags
Where shortcutRecorder
is an IBOutlet
to the SRRecorderControl
.
In order to restore saved keyboard shortcuts when the user opens the preferences window again, I load the KeyCombo.code
and KeyCombo.flags
attributes from defaults, and need to restore them to the `SRRecorderControl.
I am trying to do:
[shortcutRecorder setKeyCombo:[
PTKeyCombo keyComboWithKeyCode:
[shortcutRecorder keyCombo].code
modifiers:[shortcutRecorder cocoaToCarbonFlags:[shortcutRecorder
keyCombo].flags]]];
But this causes an error: Sending 'id' to parameter of incompatible type 'KeyCombo' (aka 'struct_KeyCombo')
I thought this might be because setKeyCombo
takes a KeyCombo
object and not a PTKeyCombo
object, so I changed it:
[shortcutRecorder setKeyCombo:[
KeyCombo keyComboWithKeyCode:
[shortcutRecorder keyCombo].code
modifiers:[shortcutRecorder cocoaToCarbonFlags:[shortcutRecorder
keyCombo].flags]]];
But now I receive the error: Receiver type 'KeyCombo' (aka 'struct_KeyCombo') is not an Objective-C class
I'm not sure how to go about creating a valid object to pass to setKeyCombo
. Any tips on the best way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
SRMakeKeyCombo(code, flags)
Try
SRMakeKeyCombo(code, flags)