我可以让此代码与快捷方式记录器一起使用吗?

发布于 2024-07-26 17:11:01 字数 2586 浏览 6 评论 0原文

我有这段代码(如下)来创建可自定义的热键。

OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData)
{
    EventHotKeyID hkCom;
    GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom);
    HotKeyController *controller = (HotKeyController *)userData;
    int l = hkCom.id;
    switch (l) {
        case 1: [controller->window makeKeyAndOrderFront:NSApp];  
            break;
        case 2: [controller->searchWindow makeKeyAndOrderFront:nil];
            break;
        case 3: [controller->entryWindow makeKeyAndOrderFront:nil];
            break;  
    }
    return noErr;
}

- (void)awakeFromNib
{
    //Register the Hotkeys
    EventHotKeyRef gMyHotKeyRef;
    EventHotKeyID gMyHotKeyID;
    EventTypeSpec eventType;
    eventType.eventClass=kEventClassKeyboard;
    eventType.eventKind=kEventHotKeyPressed;


    InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,(void *)self,NULL);

    gMyHotKeyID.signature='htk1';
    gMyHotKeyID.id=1;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeMain"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeMain"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersMain"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

    gMyHotKeyID.signature='htk2';
    gMyHotKeyID.id=2;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeSearch"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeSearch"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersSearch"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

    gMyHotKeyID.signature='htk3';
    gMyHotKeyID.id=3;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeEntry"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeEntry"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersEntry"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

}

但是代码是为了通过弹出框使热键可定制的,我该如何制作它才能与 快捷录音机一起使用 按钮或字段。 在他们的示例应用程序(来自编写代码的人)中,他们使用了通过操作连接到控制器以选择热键的弹出框和连接到 NSUserDefaultsController 的文本字段以显示它。 我如何使快捷记录器字段/按钮选择热键,因为目前我将操作和用户默认控制器连接到它,但它不起作用(即使热键工作)。 需要如何更改代码才能使其正常工作或使其执行应该执行的操作?

I have this code(below) to create a customizable Hot Key.

OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData)
{
    EventHotKeyID hkCom;
    GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom);
    HotKeyController *controller = (HotKeyController *)userData;
    int l = hkCom.id;
    switch (l) {
        case 1: [controller->window makeKeyAndOrderFront:NSApp];  
            break;
        case 2: [controller->searchWindow makeKeyAndOrderFront:nil];
            break;
        case 3: [controller->entryWindow makeKeyAndOrderFront:nil];
            break;  
    }
    return noErr;
}

- (void)awakeFromNib
{
    //Register the Hotkeys
    EventHotKeyRef gMyHotKeyRef;
    EventHotKeyID gMyHotKeyID;
    EventTypeSpec eventType;
    eventType.eventClass=kEventClassKeyboard;
    eventType.eventKind=kEventHotKeyPressed;


    InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,(void *)self,NULL);

    gMyHotKeyID.signature='htk1';
    gMyHotKeyID.id=1;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeMain"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeMain"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersMain"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

    gMyHotKeyID.signature='htk2';
    gMyHotKeyID.id=2;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeSearch"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeSearch"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersSearch"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

    gMyHotKeyID.signature='htk3';
    gMyHotKeyID.id=3;
    if([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeEntry"]!=-999) {
        RegisterEventHotKey([[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyCodeEntry"], [[NSUserDefaults standardUserDefaults] integerForKey:@"hotkeyModifiersEntry"], gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
    }

}

But the code was made to make the Hotkey Customizable via a Popup Box, how would I make it so it would work with Shortcut Recorders Button Or Field. In their example application (from the person who made the code) they used a Popup box connected via an action to the Controller to Choose the Hotkey and a Text Field connected to a NSUserDefaultsController to Display it. How would I make the Shortcut Recorders Field/Button choose the Hotkey because at the moment i connect the action to and the User Deault Controller to it but it doesn't work (i.e Make the Hotkey Work) . How would the code need to be changed to make it work or make it do what is should do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

小草泠泠 2024-08-02 17:11:01

您需要从 SRRecorderControl 获取 KeyCombo。 它具有修饰符标志和虚拟键代码,您将在 Carbon Event 热键中使用它们。 在将修改器标志传递给 RegisterEventHotKey 之前,不要忘记告诉 SRRecorderControl 将它们从 Cocoa 转换为 Carbon。

您可以在 SRRecorderControl 和 SRCommon 标头中找到所有这些内容。

You'll need to get the KeyCombo from the SRRecorderControl. That has the modifier flags and virtual key-code, which you'll use in your Carbon Event hot-key. Don't forget to tell the SRRecorderControl to translate the modifier flags from Cocoa to Carbon before you pass them to RegisterEventHotKey.

You'll find all of these in the SRRecorderControl and SRCommon headers.

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