Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6739227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:27:44+00:00 2026-05-26T11:27:44+00:00

I am writing a Cocoa application and I’d like to implement a global hotkey

  • 0

I am writing a Cocoa application and I’d like to implement a global hotkey function.
I implemented the ShortcutRecorder.framework from Waffle Software and I added a customView to my xib. Then I subclassed the CustomView to SRRecorderControl. Now I see the Recorder in my Window, but how can I get the KeyCombo and how can I react on that?

I implemented the keyComboDidChange method with no luck to get the keycode. What am I doing wrong?

Here is my code for getting the keycode:

- (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCombo)newKeyCombo
{
    if (aRecorder == shortcutRecorder)
    {
        NSLog{"We got a new Key Combo");
    }
}

shortcutrecorder is my IBOutlet btw.

Do I have to implement a protocol or setDelegate:self or something like that?

Edited to add

Actually I have declared my shortcutRecorder outlet in my Preferences.h. Then in the Identity Inspector I put “Preferences” as Custom Class for Files Owner in and I connect the delegate to my Shortcut Recorder… but the keyComboDidChange is never called … I don’t understand why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:27:45+00:00Added an answer on May 26, 2026 at 11:27 am

    Let me explain the steps I took to get it working:

    • Create a window xib
    • The file’s owner of this class is, in my case, PreferencesWindowController
    • Create a referencing outlet from the window to the file’s owner, by right clicking the window and dragging it to the file’s owner
    • Add the custom view to your window
    • You have to connect the delegate of the ShortcutRecorder to the “File’s owner”. To do this, right-click the SRRecorderControl and drag the delegate to the “File’s owner” on your left.

    After this: the ShortcutRecorder only records the hotkey and leaves it to you what to do with it. You need to use the PTHotKeyCenter (which is shipped with ShortcutRecorder) or you could implement the shortcut handling yourself.

    The ShortcutRecorder contains a great demo which demonstrates the use of the ShortcutRecorder in combination with the PTHotKeyCenter. It works like this:

    • Listen to events from the ShortcutRecorder (which you already do, but without setting the delegate)
    • Check if the globalHotKey variable is set
    • If so, unload the previous hotkey
    • Init a new hotkey with the settings from the ShortcutRecorder
    • Set the target and action to actually capture the hotkey, once pressed
    • Save the hotkey to the shared center (from this moment on, the hotkey will work)

    Little sample, from their source:

    if (globalHotKey != nil)
    {
        [[PTHotKeyCenter sharedCenter] unregisterHotKey: globalHotKey];
        [globalHotKey release];
        globalHotKey = nil;
    }
    
    globalHotKey = [[PTHotKey alloc] initWithIdentifier:@"SRTest"
                                               keyCombo:[PTKeyCombo keyComboWithKeyCode:[shortcutRecorder keyCombo].code
                                                                              modifiers:[shortcutRecorder cocoaToCarbonFlags: [shortcutRecorder keyCombo].flags]]];
    
    [globalHotKey setTarget: self];
    [globalHotKey setAction: @selector(hitHotKey:)];
    
    [[PTHotKeyCenter sharedCenter] registerHotKey: globalHotKey];
    

    The only thing left to do is the hotkey handler:

    - (void)hitHotKey:(PTHotKey *)hotKey
    {
        NSLog(@"Hotkey pressed!");
    }
    

    You could easily save the hotkey settings to the UserDefaults to load them every time you application starts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Cocoa application that makes use of the ParseKit framework (
I'm writing a Cocoa application in Objective-C, and I would like to be able
Writing an application in Cocoa that will take input from the user, format it
i need a simple logging solution while writing Cocoa/OpenGL application in C++. I'd like:
I am writing a Cocoa application with Mono embedded. I want to run and
I'm writing a Cocoa application that installs itself as an menulet in the menu
I'm writing a Cocoa application where I have an auto generated app delegate:(MyAppDelegate.h/MyAppDelegate.m) So
So, I'm writing a Cocoa application that needs to be able to display web
The Problem I'm writing a Cocoa application and I want to raise exceptions that
I am writing a Mac Cocoa application that will manipulate database files, which can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.