Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to unbind global shortcut #306

Open
lidortal opened this issue Oct 29, 2015 · 4 comments
Open

Fail to unbind global shortcut #306

lidortal opened this issue Oct 29, 2015 · 4 comments

Comments

@lidortal
Copy link

Hi, how do I unbind global shortcut?
I did the following:
Mousetrap.bindGlobal('ctrl+s', function() {
alert("Hi!");
});
....
Mousetrap.unbind('ctrl+s');

However when pressing ctrl+s I still get the Hi! message.
Thanks!

@kafeltz
Copy link

kafeltz commented Oct 29, 2015

Indeed, I tried it too in jsfiddle and I wasn't able to unbind it.

What I could do to temporary solve is to bind it again with empty function callback.

Mousetrap.bindGlobal('ctrl+s', function() { alert("Hi!"); });
Mousetrap.bindGlobal('ctrl+s', function() { /* do nothing */ });

@desertdev
Copy link

I have run into the same issue when using bindGlobal and then later needing to clear everything with Mousetrap.reset().

My keyboard shortcuts are built dynamically based on server response, is there a way to get all the current Mousetrap bindings programmatically in order to assign them empty functions?

@timmyomahony
Copy link

timmyomahony commented Aug 5, 2016

+1 for this. I want esc to close the sidebar when it's open but I also need esc to do other things throughout the application. I'm using Ember so the keypress bind/unbinds are dynamic as components are rendered. unbinding one component that listens to esc unbinds them all.

@davidbarral
Copy link

+1. A use case for this is to have global shortcuts for different pages in an app. It must be possible to unbind them. Also I think It is programmer friendlier to have the methods in pairs bind/unbind bindGlobal/unbindGlobal (I expected this behaviour and it didn't work 😅). We are currently using #353 in some apps. Seems to be working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants