使用快捷方式记录器保存/加载键盘快捷键?

发布于 2024-12-19 04:13:04 字数 1432 浏览 4 评论 0原文

我正在 XCode4 中开发 Cocoa/Objective-C 应用程序,它使用 shortcutrecorder 来记录键盘快捷键并将它们保存为默认值。

我正在保存记录器中的 KeyCombo.codeKeyCombo.flags 属性,即:

[shortcutRecorder KeyCombo].code
[shortcutRecorder KeyCombo].flags

其中 shortcutRecorderIBOutlet > 到 SRRecorderControl

为了在用户再次打开首选项窗口时恢复保存的键盘快捷键,我从默认值加载 KeyCombo.codeKeyCombo.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2024-12-26 04:13:04

尝试 SRMakeKeyCombo(code, flags)

Try SRMakeKeyCombo(code, flags)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文