

Keymaster.js: micro-library to add keyboard shortcuts  - gbaygon
https://github.com/madrobby/keymaster#readme

======
glimcat
I've been using shortcut.js for keyboard shortcuts. Works great.

<http://www.openjs.com/scripts/events/keyboard_shortcuts/>

~~~
iusable
Cool. How would you compare that to keymaster.js?

~~~
glimcat
Roughly, keymaster.js is focused on being small, while shortcut.js has been
through a few iterations and is focused on being feature-rich. But they are
both fairly small and they have many of the same features.

------
bbx
I have a question about the way keyboard shortcuts are implemented: are the
keys mostly chosen for their value or their position?

For example (and please correct me if I'm mistaken), "Copy" is "C" because
it's the first letter, and "X" is "Cut" because it looks like scissors. But
"V" was chosen because it's next to the two others, despite not hinting at
"Paste" at all.

The reason I come up with that question is that I use a French keyboard
(AZERTY) which modifies a dozen of key positions, and it makes some shortcuts
hard to execute. Sometimes, they're even _impossible_ to execute. For example,
the numbers row needs SHIFT to type a number. In QWERTY, to get a "1" you just
type "1" but on AZERTY you type "SHIFT+&".

I'm sure other international keyboard layouts have the same issue and wondered
how those who implement those shortcuts deal with that.

~~~
jarek-foksa
When you attach 'keypress' event it will give char code which can be easily
converted to sign, e.g.:

    
    
        document.addEventListener('keypress', function(event) {
          sign = String.fromCharCode(event.charCode);
    
          if (sign === 'A') {
            console.log('Pressed shift+a');
          }
          else if (sign === 'c' && event.ctrlKey) {
            console.log('Pressed ctrl+c');
          }
        });
    

I have tested this technique with several layouts (azerty, dvorak, bepo) and
it seems to be working fine. For special keys such as enter, esc or backspace
you will have to listen for 'keydown' event instead.

------
skadamat
Someone should make a JS framework to easily integrate 'Next page' / 'previous
page' and map it to a universal keyboard shortcut that isn't used for other
things.

It's not as easy as it should be to go from page to page on some sites and
would be cool if there was a way to do it via the keyboard!

~~~
wisty
It's already part of HTML -
[http://diveintoaccessibility.info/day_15_defining_keyboard_s...](http://diveintoaccessibility.info/day_15_defining_keyboard_shortcuts.html)

~~~
riffraff
I don't think the liks is about the OP says (e.g next page/prev page mapped to
arrows, as plenty of sites do).

Noticeably, there is no access key in the prev/next links in
diveintoaccessibility :)

------
radagaisus
We are using it without complaints so far. We just changed one line (#62) so
it would work inside inputs and textareas. It's just 150 lines of code, so
there's no reason not to read the source before using it!

------
Kevindish
Could you use this for controls in a javascript game? :-) Thanks. I am
starting to make games, and want to use keyboard keys now.

------
sirch
Thanks for posting. The source code is going to help me improve a key-powered
project I am working on.

------
atomical
I was actually thinking about how to do keyboard shortcuts today. I'm glad I
came across this.

------
drostie
There are no shortcuts, only Zuul?

I approve of this project name. :D

~~~
ams6110
Just don't pair it up with something called gatekeeper.js

------
k-a-r
Very cool, H5F for starter. Thanks for posting this.

------
jakejake
super cool - thanks for posting!

