ccampbell / mousetrap

Simple library for handling keyboard shortcuts in Javascript
https://craig.is/killing/mice
Apache License 2.0
11.66k stars 968 forks source link

wildcards? #374

Open howiepaul opened 7 years ago

howiepaul commented 7 years ago

Hi, great project! Im using it to cycle through an alphabetical list with ease.

How can I add a wildcard though? I dont want to add 26 lines to reflect each letter: Mousetrap.bind('b', function() {window.location.href="#b";});

I want one line for: Mousetrap.bind('"this-letter"', function() {window.location.href="#this-letter";});

Any thoughts?

Thanks

joshgcampbell commented 7 years ago

Have you thought about creating a foreach loop which iterates through each letter in the alphabet? You could run Mousetrap.bind with each letter that way in just a few lines.

bernardoadc commented 6 years ago

It would solve it yes, but in my case I want any keyup