Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DDHotKey to create user-definable Hot-Key in my Cocoa Application

Tags:

cocoa

ddhotkey

Having successfully implemented Dave DeLong's DDHotKey I'm now wondering if it's possible to make the hot-key user definable?

The only code in the app that deals specifically with the HotKey is:

- (IBAction)registerHotKey:(id)sender {
DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
[c registerHotKeyWithKeyCode:1 modifierFlags:NSControlKeyMask target:self action:@selector(activateMain:) object:window];
[c release];

and

- (IBAction) unregisterHotKey:(id)sender {
DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
[c unregisterHotKeyWithKeyCode:1 modifierFlags:NSControlKeyMask];
[c release];
}

I'm thinking that it would be necessary to re-write those sections but I'm not sure if that's true, and if it is true I'm not sure where to begin looking.

It seems to me that it would be necessary to capture keyboard input and perhaps save it as a string...but beyond that I'm really unsure as to how to proceed.

like image 726
Zrb0529 Avatar asked Nov 20 '25 09:11

Zrb0529


1 Answers

Yep, you can make them user-configurable. You'll need some sort of UI for the user to type a keyboard shortcut themselves (I've used Shortcut Recorder in the past). The info you get from that control should be sufficient to pass to the DDHotKey registration functions.

like image 178
Dave DeLong Avatar answered Nov 22 '25 22:11

Dave DeLong