cocoabits / MASShortcut

Modern framework for managing global keyboard shortcuts compatible with Mac App Store. More details:
http://blog.shpakovski.com/2012/07/global-keyboard-shortcuts-in-cocoa.html
BSD 2-Clause "Simplified" License
1.52k stars 220 forks source link

Shortcut conflict checker does not check if shortcut is enabled or not #33

Closed chendo closed 10 years ago

chendo commented 10 years ago

When MASShortcut checks existing shortcuts for conflicts, it does not take in account whether or not the existing shortcut is enabled or not.

Use case: Cmd+Option+Space is taken by the system for "Select next source in input", but is disabled by default. However, trying to assign to this with MASShortcut will cause it to error. Is this because it's not possible to register a shortcut when one exists but is disabled?

shpakovski commented 10 years ago

Hello Jack, it looks like there is a key kHISymbolicHotKeyEnabled which can help. Could you please try to modify some code in MASShortcut.m to check how it works?

CFNumberRef code = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyCode);
CFNumberRef flags = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyModifiers);
CFNumberRef enabled = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyEnabled);

if (([(__bridge NSNumber *)code unsignedIntegerValue] == self.keyCode) &&
    ([(__bridge NSNumber *)flags unsignedIntegerValue] == self.carbonFlags) &&
    ([(__bridge NSNumber *)enabled boolValue] )) {

Sorry for the late reply.

chendo commented 10 years ago

Yeah, I stumbled across that key as well, although I wasn’t sure if the hotkey system was limited to one entry (regardless of active or not). I’ll have a go when I have the chance. Thanks!

On Monday, 7 April 2014 at 7:02 am, Vadim Shpakovski wrote:

Hello Jack, it looks like there is a key kHISymbolicHotKeyEnabled that can help. Could you please modify some code in MASShortcut.m to see if it works? CFNumberRef code = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyCode); CFNumberRef flags = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyModifiers); CFNumberRef enabled = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyEnabled); if (([(bridge NSNumber *)code unsignedIntegerValue] == self.keyCode) && ([(bridge NSNumber )flags unsignedIntegerValue] == self.carbonFlags) && ([(__bridge NSNumber )enabled boolValue] )) {

Sorry for the late reply.

— Reply to this email directly or view it on GitHub (https://github.com/shpakovski/MASShortcut/issues/33#issuecomment-39680635).

chendo commented 10 years ago

Sorry for super late reply, but I've confirmed this fixes the issue!

shpakovski commented 10 years ago

I pushed the change, thanks!