Why copy and paste in finder doesn't work when I use RegisterEventHotKey (Cocoa)?

a 夏天 提交于 2019-12-11 07:44:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!