Coder Social home page Coder Social logo

cocoabits / masshortcut Goto Github PK

View Code? Open in Web Editor NEW
1.5K 1.5K 220.0 564 KB

Modern framework for managing global keyboard shortcuts compatible with Mac App Store. More details:

Home Page: http://blog.shpakovski.com/2012/07/global-keyboard-shortcuts-in-cocoa.html

License: BSD 2-Clause "Simplified" License

Objective-C 94.65% Ruby 2.98% Makefile 0.33% C 0.78% Swift 1.27%

masshortcut's People

Contributors

brow avatar coder-256 avatar corybohon avatar exevil avatar gettoset avatar iluuu1994 avatar kainjow avatar kant avatar michaeljtsai avatar miximka avatar nevack avatar nikitaourazbaev avatar ninjaprox avatar nivanchikov avatar oreshinya avatar pavelkozarek avatar pedrovieira avatar pfandrade avatar pointum avatar radex avatar saagarjha avatar sfsam avatar starkos avatar stillness-2 avatar sweetppro avatar tonyarnold avatar uasi avatar vitu avatar xhacker avatar zoul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

masshortcut's Issues

Stop working after registering the same input after cancellation

First of all, thanks for this great job. It really saves a whole lot of my time.

I found a bug that a shortcut stops working after registering the same shortcut as before after cancelling it. This occurs in the demo app too.

Steps to Reproduce

  • Register a shortcut, let me say it's cmd+j.
  • Cancel the shortcut
  • Register the same shortcut, cmd+j.
  • And then the shortcut stops working.

Is there any documentation I missed or is this a bug?

Thanks in advance.

Register shortcuts in non-exclusive mode

During my work on the support for older OS X versions I stumbled upon a bug where a shortcut would refuse to register saying it’s already registered. This lead me to the kEventHotKeyExclusive option used for registering the Carbon hot keys.

In the exclusive mode the RegisterEventHotKey call will refuse to register a hotkey that already exists. We have to handle that case somehow, currently we just crash. But it’s a hard case to handle in the UI, because Carbon won’t tell us which app registered the hotkey before us. (What should we tell the user? Just saying that the shortcut is already used is dumb.)

@shpakovski, what do you think about dropping the exclusive mode? Then the hotkey registration won’t fail even if the shortcut is already registered. And the worst that can happen is that two apps will respond to the same shortcut, which is a case that’s pretty easy to understand and fix for a user.

Isn't carbon api fully deprecated?

I was trying to figure out how MASShortcut works and found that it uses InstallEventHandler call. I've read that Carbon API is now fully deprecated and doesn't support 64-bit systems. I assume this eventually will be an issue, Apple also cannot be thrilled about use of deprecated stuff. Can this potentially be a problem? Has anyone ever been warned about using it in App Store?

I also know there are Quartz Event Taps that seem to allow doing the same thing. I wonder why didn't you guys switch to that? Are there any issues with that or is it less reliable or has a limiting functionality?

Possibility to receive an event on keyUp?

I'm trying to build a utility using this library that will respond to a shortcut being pressed, but also handle when that shortcut is released.

The events themselves are given out through NSEvents as keyDown and keyUp, but attaching MASShortcut to a hotkey prevents the default NSEvents from firing.

Is it possible to gather the keyUp event from within MASShortcut?

Compiler warning for NSAccessibilityPriorityKey

The only warning I get when compiling my project using MASShortcut is from MASShortcut:

/Users/user/repos/DisturbMeNot/Pods/MASShortcut/Framework/MASShortcutView.m:141:31: Comparison of address of 'NSAccessibilityPriorityKey' not equal to a null pointer is always true

Is this basically a check to see if the OS version is >= 10.9?

Hotkey handler not firing right away when a menu of the handling app is open

I noticed that the hotkey handler does not fire right away when a menu (popup or menu bar) of the app that installed the hotkey is open. Only when the menu is closed does the hotkey fire.

To reproduce:

  • Open an app that uses a shortcut
  • Click on the "File" menu in the menu bar (or any other menu)

→ Important: it has to be the menu of the app handling the hotkey

  • With the menu open, press the hotkey

→ The handler will not be called until the menu closes

Expected: the handler should always fire as soon as the hotkey is pressed.

Note: if the menu belongs to another app, the handler is called right away.

Introduce a separate class for formatting shortcuts

Formatting a shortcut (ie. producing a string description of its modifiers or keys) should be refactored into a standalone clas. This will give use options (⌘^ or Command-Control, uppercase or lowercase, ASCII or Unicode) and is simply the right thing to do. Since formatting depends on the active keyboard layout (see the spec), it would be great to turn this into an explicit setting. That way we could then run automated formatting tests with various keyboard layouts – and we could also probably write automated tests for code that depends on shortcut formatting, such as shortcut validation (see #62).

The keyCodeString property could then be simply deprecated and later removed, or we could make it call a shared default formatter with the appropriate settings. The keyCodeStringForKeyEquivalent should be probably deprecated, since it’s only used during validation. It’s also used when somebody wants to assign a shortcut as a key equivalent of a menu item, but that use case would be better served directly by a category on NSMenuItem (maybe even bindable).

CocoaPods with frameworks

If I enable framework use in CocoaPods (for Swift support), like so:

target :Mac do
  platform :osx, '10.10'
  use_frameworks!
  link_with 'Mac'

  pod 'MASShortcut',      '~> 2.3'
end

MASShortcut won't work. Trying to #import a header doesn't work, and importing the MASShortcut module will silently fail — will compile, but no symbols will actually be imported.

I pinned down the issue to the the MASShortcut-umbrella.h file generated by CocoaPods:

#import <Cocoa/Cocoa.h>

#import "MASDictionaryTransformer.h"
#import "MASHotKey.h"
#import "MASKeyCodes.h"
#import "MASLocalization.h"
#import "MASShortcut.h"
#import "MASShortcutBinder.h"
#import "MASShortcutMonitor.h"
#import "MASShortcutValidator.h"
#import "MASShortcutView+Bindings.h"
#import "MASShortcutView.h"
//#import "Shortcut.h"

FOUNDATION_EXPORT double MASShortcutVersionNumber;
FOUNDATION_EXPORT const unsigned char MASShortcutVersionString[];

I suppose that the fact that it generates both imports to all headers automatically and also adds your import-all Shortcut.h confuses the compiler somehow. When I commented out that import, it works now (I can now import MASShortcut in Swift, no problem). But I don't know how to fix it for everyone.

Event deadlock in MASShortcutView.m

I'm using the MASShortcutView inside an NSTableView which is inside an NSPopover. The popover autoreleases its memory with a delay on closing it. What this causes is that the MASShortcutView inside the table cell gets deallocated with a delay thereby triggering [self activateEventMonitoring:NO]; with a delay as well. Since the dealloc happens after this delay, and if another NSPopover is opened in the mean time, the [self activateEventMonitoring:YES]; triggers before the dealloc causing the event monitor to be re-registered first and then removed (incorrectly) on the dealloc.

To be clear:
Open popover -> Click on an MASShortcutView to trigger recording -> Set the new shortcut -> Close popover -> Open popover -> Click again on an MASShortcutView -> Can't set the new shortcut since the dealloc happens around this time for the old popover.

Maybe found a potential memory leak of the elements in globalHotKeys

When I hit the hot keys composed of ⌃⌘Space (a system-wide shortcut), isTakenError: method will early return (excute return YES; )
 return YES

BUT on return, globalHotKeys still not be released, we have not an opportunity to release the globalHotKeys:
 globalHotKeys still not be released

So I wonder that is this a potential memory leak? ( Please see the comment above return YES; )

- (BOOL)isTakenError:(NSError **)outError
{
    CFArrayRef globalHotKeys;
    if (CopySymbolicHotKeys(&globalHotKeys) == noErr) {

        // Enumerate all global hotkeys and check if any of them matches current shortcut
        for (CFIndex i = 0, count = CFArrayGetCount(globalHotKeys); i < count; i++) {
            CFDictionaryRef hotKeyInfo = CFArrayGetValueAtIndex(globalHotKeys, i);
            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])) {

                if (outError) {
                    NSString *description = NSLocalizedString(@"This combination cannot be used because it is already used by a system-wide "
                                                              @"keyboard shortcut.\nIf you really want to use this key combination, most shortcuts "
                                                              @"can be changed in the Keyboard & Mouse panel in System Preferences.",
                                                              @"Message for alert when shortcut is already used by the system");
                    NSDictionary *info = [NSDictionary dictionaryWithObject:description forKey:NSLocalizedDescriptionKey];
                    *outError = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:info];
                }
                /* On return, globalHotKeys still not be released, is this a potential memory leak?
                 * Perhaps there should be a CFRelease( globalHotKeys );
                 */
                return YES;
            }
        }


        CFRelease(globalHotKeys);
    }
    return [self isKeyEquivalent:self.keyCodeStringForKeyEquivalent flags:self.modifierFlags takenInMenu:[NSApp mainMenu] error:outError];
}

xcode 6.2 compiling issues.

Hello.

I'm using xcode beta and I'm trying to use MASShortcut within a swift project.

After importing MASShortcut in bridging header file I'm getting the following error during compilation:

<unknown>:0: error: /path/to/project/Pods/Headers/MASShortcut/MASShortcut.h:49: expected a type

And this is a MASShortcut.h:49:

+ (MASShortcut *)shortcutWithEvent:(NSEvent *)anEvent;

Maybe NSEvent is not in the carbon anymore?

I solved the issue by adding #import <Cocoa/Cocoa.h> on top of the MASShortcut.h, but I'm unsure if it's a proper solution. Also, if the problem is related to api changes, maybe it'd be a good idea to add the fix to the library as well.

Thanks.

Appearance synthesize on 10.9

I built my app on Mavericks and got a few build errors in MASShortcut.
screen shot 2013-10-19 at 2 19 20 pm

I fixed this by adding:

@synthesize appearance = _appearance;

here. I'm not sure if this is just some of the build settings I have so I didn't want to submit a pull request just yet. If this is an issue I can submit that change as one.

NSPanel to move front issue

It seems that when you register the shortcut and trigger the registered shortcut to open the app, the app opens but the NSPanel window does always show up on the front even if you already closed the panel, because the instance of the panel is still retained.

This does not occur when you manually select the app icon from the dock; it only occurs when launched via keyboard shortcut.

Is there any way to prevent the panel from being displayed when you trigger the shortcut? I use NSColorWell and NSColorPanel.

Fix documentation markup for CocoaDocs

Looking at the nice documentation generated over at CocoaDocs, the documentation markup used in our source code doesn’t work correctly. There are several ways to mark up the documentation – the current one works in Xcode, but apparently not on CocoaDocs. We should take a look at some other library to see what works for them.

Creating a shortcut works sporadically

The first time I click the shortcutview and create the shortcut, it works, but if I click it again, then sometimes it doesn't work. I can click the option+shift and it shows, but when I click the last button (let's say "R"), then nothing happens. When I lift up the keys again, the shortcut view goes blank and I can try again and again, but with no result.

Has anybody else tried this? Any solution?

MASShortcutGlyph needs a `typedef`

Suggested:

typedef enum {
...
} MASShortcutGlyph;

This allows the header file to be included in multiple different places without causing duplicate symbol _MASShortcutGlyph.

MASShortcutView doesn't show modifier keys on press

If you only press modifier keys, like cmd, option and ctrl, the view doesn't display their characters (see the behaviour of the official Twitter app's shortcut recorder). It only displays them when you finalise the shortcut.

The fix is to change line 301 in MASShortcutView.m to include NSFlagsChangedMask:

eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:(NSKeyDownMask | NSFlagsChangedMask) handler:^(NSEvent *event) {

Support for F keys by themselves

I tried the demo, but it appears that the f keys can't be set without a modifier, is this something that can be fixed or is this a limitation of osx?

MASShortcutBinder "this class is not key value coding-compliant for the key ..."

I've recently switched from MASShortcut 1.0 to 2.0 and now I've been experiencing this bug:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MASShortcutBinder 0x60800004cfc0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key Shortcut Open Last.'

Here's the code I'm currently using (which worked before I updated from MASShortcut registerGlobalShortcutWithUserDefaultsKey:handler: to MASShortcutBinder bindShortcutWithDefaultsKey: toAction:):

[[MASShortcutBinder sharedBinder] bindShortcutWithDefaultsKey:kPrefsShortcutOpenLastFmUserURLKey toAction:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            // do something
        });
    }];

When debugging, my program completely crashes at this point giving the following error message on the console:

    0   CoreFoundation                      0x00007fff9227166c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff925b576e objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff92271209 -[NSException raise] + 9
    3   Foundation                          0x00007fff8adc23dd -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 226
    4   MASShortcut                         0x000000010014ae9a -[MASShortcutBinder valueForUndefinedKey:] + 186
    5   Foundation                          0x00007fff8acdfbf8 -[NSObject(NSKeyValueCoding) valueForKey:] + 385
    6   Foundation                          0x00007fff8acf862e -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 255
    7   AppKit                              0x00007fff83d87e0d -[NSObjectParameterBinder _updateObject:observedController:observedKeyPath:context:] + 622
    8   AppKit                              0x00007fff83d7f293 -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 758
    9   MASShortcut                         0x000000010014a705 -[MASShortcutBinder bindShortcutWithDefaultsKey:toAction:] + 309
    10  Muzzy                               0x0000000100013e6d __38-[AppDelegate listenToGlobalShortcuts]_block_invoke + 365
    11  libdispatch.dylib                   0x000000010016e2bb _dispatch_call_block_and_release + 12
    12  libdispatch.dylib                   0x0000000100168d43 _dispatch_client_callout + 8
    13  libdispatch.dylib                   0x0000000100177d9f _dispatch_main_queue_callback_4CF + 1370
    14  CoreFoundation                      0x00007fff921c4c79 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    15  CoreFoundation                      0x00007fff9218130f __CFRunLoopRun + 2159
    16  CoreFoundation                      0x00007fff92180858 CFRunLoopRunSpecific + 296
    17  HIToolbox                           0x00007fff8b4bfaef RunCurrentEventLoopInMode + 235
    18  HIToolbox                           0x00007fff8b4bf86a ReceiveNextEventCommon + 431
    19  HIToolbox                           0x00007fff8b4bf6ab _BlockUntilNextEventMatchingListInModeWithFilter + 71
    20  AppKit                              0x00007fff83cfcf81 _DPSNextEvent + 964
    21  AppKit                              0x00007fff83cfc730 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
    22  AppKit                              0x00007fff83cf0593 -[NSApplication run] + 594
    23  AppKit                              0x00007fff83cdba14 NSApplicationMain + 1832
    24  Muzzy                               0x000000010000a6d2 main + 34
    25  libdyld.dylib                       0x00007fff870d25c9 start + 1
    26  ???                                 0x0000000000000003 0x0 + 3

Any ideas on what's making this crash? It's so weird because I am listening to more shortcuts the same way as above, with other shortcut constant identifiers, and it's passing my debugging without a problem. Only this one is making my app crash.

NSShiftKeyMask et al. do not appear to be working

I am using base SDK 10.10 with a deployment target of 10.9.
There were around 9 build errors with 2.1.2 using cocoa pods.
The errors were from the NSShiftKeyMask et al. not being defined even though Carbon.h was
imported at the top of the file. A search of Carbon.h revealed they were not there.
A Google search revealed they are defined in AppKit/NSEvent.h

My fix was to add #import AppKit/NSEvent.h to the file MASKeyCodes.h
I'm not sure why this happened as I had been using MASShorcut for a while with no issues. I had modified my copy to customize the font color. This issue appeared after I updated the pods to overwrite my font color change code since it wasn't needed anymore in my application as the design had changed.

After launching an external method stops working

Hi! I found a problem after restarting my application and pressing the hotkeys i set in the preferences window.

I'm registering the shortcuts in the applicationDidFinishedLaunching method. Something like this:
[MASShortcut registerGlobalShortcutWithUserDefaultsKey:@"hotkeyShortcut" handler:^{
NSLog(@"Run the method");
[[SomeObject sharedInstance] action];
NSLog(@"Run over");
}];

The first time I press my shortcut keys after running the app works just fine but the afterwards stop functioning.
I could observe that if I run some methods inside the app delegate class (which contains the register methods) all work fine.

I would also like to add that if I re-enter the prefs window and reset the shortcut keys the everything seams to work fine until I restar the app.

Any ideas why is doing this?
Thanks in advanced

Cris

PS: here is a small stripped down version of my app in whom it doesn't work. I've included my preferences plist which contains the following hotkeys combination: Cmd+Shift+0. After the first press, NSUserDefaults seem to update and reset the hotkey. If I remove the NSOulineView it seams to work fine.

Here is the link to download the project: https://www.dropbox.com/s/8nwk0f4vpc528di/test.zip

Doesn't work with Xcode 6.1 Beta 2

It looks like MASShortcutView doesn't work when compiled on Xcode 6.1 Beta 2. It works perfectly fine on 6.0 Beta 7, but after opening the project in new Xcode — the view doesn't render on screen.

I did some digging and it looks like the rendering method is reached, but [NSCell drawWithFrame:inView:] simply doesn't do the right thing.

Unfortunately I don't have enough knowledge about cells or MASShortcut to figure out if it's Xcode at fault or MASShortcut does something wrong.

Does anyone have any clue? Maybe a workaround?

Release 2.0.0

To be done:

  • Simplify the demo project to the basic use case
  • Add CocoaPods installation instructions
  • Add CocoaPods installation instructions for staying on the 1.x branch
  • Test CocoaPods installation
  • Add a documentation notice for people who would like to migrate from Shortcut Recorder

Non ARC Version ?

How can i use it in my non-arc project ?
Please provide a non-arc version. Thanks.

Permission to use

Hi Vadim,

I'm building my own shortcut reader control, and I was looking for some inspiration on how to convert a keyCode or modifierFlags to a NSString.
You've done it perfectly, and I would be great if I could use it in my own repository.

Do I have your permission to do so?

Shortcut validation doesn’t consider different keyboard layouts

Test case: Using the US keyboard layout, assign the ^2 shortcut to a menu item and switch to the Czech keyboard layout. Now trying to record a shortcut will pass the validation, although the shortcuts have the same key code and modifiers and are in conflict. See #60 for previous discussion. No idea if we can handle this better, but at least we could describe the failing case in the spec and the docs.

MASShortcut & MASPreferences

Loving MASShortcut, but I seem to be struggling to use it and MASPreferences together. Is there any chance of a demo project that also uses MASPreferences somewhere? Thanks.

Shortcut handler fired when "changing" shortcut to it's current value

Steps to Reproduce

  1. Click the MASShortcutView to record a new shortcut.
  2. Type Cmd+F10
  3. Click the MASShortcutView to change the shortcut.
  4. Type Cmd+F10

Expected Behaviour

Shortcut handler does not fire since the user is actually recording the shortcut.

Actual Behaviour

Shortcut handler is fired.

Video

changing_shortcut

Requires ARC/GC ?

I tried to add MASShortcut to my project, but I got the following error:

MASShortcut/MASShortcutView+UserDefaults.m:43:13: @synthesize of 'weak' property is only allowed in ARC or GC mode

So I tried to enable automatic reference counting in my project, but that didn't work, as my whole codebase is based on manual memory management.

I tried to just remove the weak property in

MASShortcutView+UserDefaults.m:
...
@Property (nonatomic, readonly, weak) MASShortcutView *shortcutView;

But that caused a bunch of other problems. For instance I often get EXC_BAD_ACCESS on:
MASShortcutView.m:168:
: _shortcutValue ? _shortcutValue.description : @"");

It seems that your framework is written with ARC in mind.. is there anyway to get it working with a non-ARC project?

Disable hotkey during hotkey assignment

If a user assigns a hotkey and then presses that hotkey during assignment, it actually fires the event the hotkey is bound to. I think a more reasonable expectation for this would be that the hotkey is temporarily unbound during assignment. Any good suggestions on how to make that happen?

Observation Leak

Everytime my view with the MASShortcutView's deallocates, I get an observation warning:

An instance 0x1002536f0 of class MASShortcutView was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0x10025ac40> (
    <NSKeyValueObservance 0x10025abd0: Observer: 0x1002591a0, Key path: shortcutValue, Options: <New: NO, Old: NO, Prior: NO> Context: 0x100074c08, Property: 0x1002574d0>
)

Apparently, this line is caused by the observer in MASShortcutView+UserDefaults.m on line 86. I see that the observer is removed on line 103, and it get's executed. But the problem persists.

add BridgeSupport generation to build

I was able to use MASShortcut almost immediately from Python, but first I had to do this:

gen_bridge_metadata -f ./MASShortcut.framework | sed -e "s/function_pointer='true'/block='true'/g" > MASShortcut.framework/Resources/BridgeSupport/MASShortcut.bridgesupport

It would be nice if this were built in to the framework. (I'm also not sure if a nicer way to do that sed exists...)

Function Modifier Key Recorded but Not Displayed in ShortcutView

If record a shortcut utilizing the function key, the fn modifier key does not display in the MASShortcutView.
EXAMPLE

  1. Click Record Shortcut.
  2. Press Function-F6.
    MASShortcutView displays "F6". I would think it should display "fn-F6", or "Function-F6". This would be consistent with how Apple identifies their use, and would distinguish from their unmodified use (e.g. F6 not modified by the fn key is rewind).

It does appear to be saved and detected correctly though.

Setting `associatedUserDefaultsKey` twice

I had some strange behavior with MASShortcut today. I was setting the shortcutView's associatedUserDefaultsKey in the view controller's viewWillAppear: method (I'm also using MASPreferences) and every other time the view appeared the shortcutView's shortcutValue was nil even though enabled was YES and the shortcutView's associatedUserDefaultsKey was set correctly.

I fixed the problem by setting the associatedUserDefaultsKey only once.

- (void)viewWillAppear
{
    if (![self.shortcutView.associatedUserDefaultsKey isEqualToString:@"GlobalShortcut"]) {
        self.shortcutView.associatedUserDefaultsKey = @"GlobalShortcut";
    }

    // other code
}

Somehow if you set associatedUserDefaultsKey twice the shortcutValue becomes nil.

This might have happened because of something else, but I'm pretty sure everything else was ok.

Setting Initial Default

What is the preferred way to set an initial user default for the hotkey combination? So first time app launched, the shortcut would be pre-defined without the user needing to record it themselves. They could change it later if they wanted.

I took a look at the demo project. I see it registering and unregistering, but that doesn't seem right way of setting the default.

P.S. This is obviously a question, not an issue. I don't see how to set the correct label for it though.

KeyCode string for KeyEquivalent depends of the current keyboard layout

When switching to non US (non-ASCII capable) keyboard layout -keyCodeStringForKeyEquivalent returns string with non-ASCII character, if a printable character was used in shortcut. But this character couldn't be used for keyEquivalent of the NSMenuItem.

I suppose it is better to use TISCopyCurrentASCIICapableKeyboardLayoutInputSource instead of TISCopyCurrentKeyboardLayoutInputSource in -keyCodeString of MASShortcut.

Preference not saving on 10.9

Hello, I noticed that on 10.9 the preference is not saved. Actually the .plist file is not created.
In one of my other sandboxed project I managed to create the prefs .plist file by calling the [NSUserDefaults resetStandardUserDefaults]; before setting the pref object and syncing.

Any ideas how to fix this?
Thanks in advance

Cris.

(Feature Request) Customizing look

Love this library, but I've been finding myself messing around with the drawRect method in the view class, so I could put another background on the view.

Would love if a more generic way of customizing the look and feel of the "button" could be made. Would that be difficult?

Not unregistering previous key when deleting

Hi! This may be an issue for others, and I'm wondering if there would be some enhancement which would avoid the issue eventually..

I use this tool a bit differently, registering many keys using the Monitor directly, not UserDefautls. I add the global monitor, using
[MASShortcut addGlobalHotkeyMonitorWithShortcut:self.shortcutView.shortcutValue

But when I try to delete the existing one (by hitting the shortCutView's Delete button and try to unregister the shortcut like so:

[MASShortcut removeGlobalHotkeyMonitor:theObject.keyShortcut];

where keyShortcut is a stored version of the actual MASShortcut object, I get the following when trying to remove it. The key in the Dictionary doesn't match as it is being interpreted as raw Unicode (here with CTRL-SHIFT-9)

The dictionary of current keys:
{
"\U2303\U21e79" = "<MASShortcutHotKey: 0x104332040>";
}

The actual key I'm trying to match to remove ('monitor' in + (void)removeGlobalHotkeyMonitor:(id)monitor)

Monitor: ⌃⇧9

All I'm doing is registering the shortcut using the MASShortcut itself as the monitor.

The issue is that when your code stores the MASShortcut as the Dictionary's Key, it uses its description, not the actual unicode keyvalue. But when trying to match with the appropriate key in the dictionary, it uses something else. In the end, the two strings do not match and the monitor doesn't get removed.

The workaround is quite simple, I store the description of the key like this:
[MASShortcut addGlobalHotkeyMonitorWithShortcut:self.shortcutView.shortcutValue.description

and thus, things get matched appropriately.

Maybe there are changes to be made to make this a bit more direct? Or maybe I'm going about this wrongly.

In the end it works great, but one has to understand that it is not the keyValue which is used as the dictionary's key, but the description.

Thoughts?

thanks for a great tool!

-Renaud

An easy way to get a string of a shortcut object?

First of all, thanks for the awesome lib. I am using it in my app, Pagehop.

I would like to show a shortcut, somewhere else in the UI (in a menu item's text).

Is there a method I should be using to convert the shortcut object saved in the user defaults to a (human-readable) string?

Thanks.

Regards,
Nikolay Tsenkov

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

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?

Re-assigning same shortcut triggers it

  1. Say I have a hotkey set up with Cmd+Ctrl+T
  2. I focus into the shortcut view
  3. I change my mind, and just want to assign the same thing, so I press Cmd+Ctrl+T

Expected behavior: Cmd+Ctrl+T is assigned, shortcut view blurs

Actual behavior: The shortcut is triggered before the shortcut view can intercept it.

Workaround would be to manually unbind on shortcut view and re-bind after blur.

This is a regression since 1.x :/

German localization strings don’t fit the recording control

@floschliep, the new German strings you have contributed in the last pull request are too long to fit the control. I have introduced some basic support for the German localization to the demo project, can you please run it in German and take a look? As an example, the Neuen Kurzbefehl eingeben “tip” displayed in the recording area is clipped. Is it possible to shorten the string? Thanks!

Only seeing XXX in UI for MASShortcutView

I am using MASShortcut v2.3.1 via CocoaPods. When I insert a MASShortcutView into my UI it works fine, but all text is shown as XXX in the UI. I suspect that Localizable.strings is not part of the pod?

I can fix it by manually copying the strings from the MASShortcut source into Localizable.strings in my own project, but hopefully that shouldn't be necessary 😄

Great library btw!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.