根据这篇文章:
调用setCanCaptureGlobalHotKeys:YES
ShortCutRecorder 控件应该允许您捕获 CMD+TAB。但是,它似乎不起作用。我自己创建了这个小应用程序来看看发生了什么:
OSStatus myHotKeyHandler(EventHandlerCallRef nextHandler, EventRef anEvent, void *userData)
{
NSLog(@"YEAY WE DID A GLOBAL HOTKEY");
return noErr;
}
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
EventHotKeyRef myHotKeyRef;
EventHotKeyID myHotKeyID;
EventTypeSpec eventType;
eventType.eventClass = kEventClassKeyboard;
eventType.eventKind = kEventHotKeyPressed;
myHotKeyID.signature = 'mhk1';
myHotKeyID.id = 1;
InstallApplicationEventHandler(&myHotKeyHandler, 1, &eventType, NULL, NULL);
OSStatus status = RegisterEventHotKey(kVK_Tab,
cmdKey,
myHotKeyID,
GetApplicationEventTarget(),
0,
&myHotKeyRef);
NSLog(@"status:%d", status);
}
@end
如果我使用cmdKey + optionKey
,那么它确实有效。
是否有另一种方法可以在我自己的 Mountain Lion 应用程序中捕获 CMD+TAB?CMD+OPTION+TAB 对我来说不够好。