问题
I use function RegisterEventHotKey() and when I try registering Cmd + C or Cmd + V, I notice that copy and paste in finder doesn't work.
I insert parameter inOptions = 0 to function RegisterEventHotKey() so it should non-exclusiv but why finder seem not to receive this hot key?
EventTypeSpec eventType;
eventType.eventClass=kEventClassKeyboard;
eventType.eventKind=kEventHotKeyPressed;
InstallApplicationEventHandler(&MyHotKeyHandler,1,&eventType,(void *)self,NULL);
EventHotKeyID gMyHotKeyID;
NSInteger keycode = 8; // 'C'
UInt32 modkey=0;
modkey+=cmdKey;
RegisterEventHotKey((int)keycode, modkey, gMyHotKeyID,
GetApplicationEventTarget(), 0, &hotkeyRef);
//
OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,
void *userData)
{
NSLog(@"test hot key");
return eventNotHandledErr;
}
Here is the code. When I click cmd+C, it show log "test hot key" but finder did not copy selected files.
*My application is agent. has menu bar and always run in the background.
回答1:
It doesn't work because when you install a hot key handler, you replace the default functionality of that key combination in every app.
来源:https://stackoverflow.com/questions/6186317/why-copy-and-paste-in-finder-doesnt-work-when-i-use-registereventhotkey-cocoa