Global shortcut work but system play Error sound
-
28-05-2021 - |
Domanda
I create global shortcut with this code:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent * theEvent) {
int modiferKeys = NSControlKeyMask | NSAlternateKeyMask;
if (([theEvent keyCode] == 7 && modiferKeys)) {
NSLog (@"%@",@"work");
}
}];
}
This code work perfect, but when some application have a focus (for example Xcode, AppStore...) the system play Error sound. How fix it? Thaks.
Soluzione
A different way to implement a global hot key is using RegisterEventHotKey
, declared in CarbonEvents.h. The docs for it might be under "legacy", but as far as I can tell from the header, it's not deprecated and is available in 64-bit code.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow