一个应用程序的全系统热键 [英] System-wide hotkey for an application

查看:187
本文介绍了一个应用程序的全系统热键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个按钮一个简单的窗口,我尝试添加一个全系统热键,所以我可以preSS,而无需这些按钮切换到该应用程序,preSS一个按钮,然后回去我在做什么。

I have a simple window with 3 buttons and I am trying to add a system-wide hot key so i can "press" those buttons without having to switch to that app, press a button and then go back to what I was doing.

类似<大骨节病> Cmd的 + <大骨节病>移 + <大骨节病> 1 preSS按钮1,<大骨节病> Cmd的 + <大骨节病>移 + <大骨节病> 2 preSS按钮2,等等。

Something like Cmd + Shift + 1 press button 1, Cmd + Shift + 2 press button 2, etc.

有什么办法可可实现这一目标(与Objective-C的)?
谢谢,code是AP preciated因为我可可总新手。

Is there any way to achieve this in Cocoa (with Objective-C)? Thanks, code is appreciated since I am a total newbie on Cocoa.

推荐答案

我也不喜欢PTHotKey,所以我最后写一个新的包装,可在这里:

I also didn't like PTHotKey, so I ended up writing a new wrapper, available here:

http://github.com/davedelong/DDHotKey

修改

2档你需要的是:

  • DDHotKeyCenter.h
  • DDHotKeyCenter.m

和你使用它是这样的:

- (IBAction) registerHotkey:(id)sender {
  DDHotKeyCenter * c = [[DDHotKeyCenter alloc] init];
  if (![c registerHotKeyWithKeyCode:kVK_ANSI_1 modifierFlags:(NSCommandKeyMask | NSShiftKeyMask) target:self action:@selector(hotkeyWithEvent:) object:nil]) {
    NSLog(@"unable to register hotkey");
  } else {
    NSLog(@"registered hotkey");
  }
  [c release];
}

- (void) hotkeyWithEvent:(NSEvent *)hkEvent {
  NSLog(@"Hotkey event: %@", hkEvent);
}

这篇关于一个应用程序的全系统热键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆