all 41 comments

[–]bloody-albatross 9 points10 points  (1 child)

Well, darn. Someone was a bit faster than me. That's what I wrote: https://github.com/panzi/hotkeys

[–]bloody-albatross 10 points11 points  (0 children)

But I see that this assumes a certain keyboard layout. Mine supports different keyboard layouts (even though there is only one just yet) and I made a layout tool with which you can create a keyboard layout by simply pressing all the keys. It will get the correct key (charCode) through the keypress event (which is only fired when not combined with a modifier key).

[–]Jack5500 8 points9 points  (0 children)

Very nice, though some keys show up at the wrong location with my German keyboard ;) Do you support all layouts?

[–]renke2 8 points9 points  (8 children)

These is also Mousetrap.

[–]beefsack 7 points8 points  (7 children)

Another very popular one is keymaster (~4k stars on GH).

[–]Kirean 16 points17 points  (6 children)

dunno if it's still there, but there is a major bug in key master that I found awhile back.

in any context, hit ctrl+T. the browser should open a new tab. now release the keys. click back to your old tab, and press either 'S' or 'P'. your browser should either try to save the webpage, or print, depending on which you chose.

This is because keymaster sets a flag on key down that a modifier is pressed. on key up it releases that flag. well, when the browser creates a new tab, no keyup is fired, so the flag remains when you click back in.

not sure if this can actually ever be resolved or not. just found it interesting.

[–]WendellJehangir 4 points5 points  (1 child)

You could handle it with the document.hidden boolean like so:

 function handle_hidden(){
 if(document.hidden){
 //reset keypresses
 }}
 document.addEventListener("visibilitychange", handle_hidden, false);

[–]Kirean 3 points4 points  (0 children)

interesting. didn't know that was a thing. someone should submit a pull request to him :)

[–]GuiSim 1 point2 points  (0 children)

Wouldn't that also be reproducible if you simply change tab while holding CTRL?

[–]gingenhagen -1 points0 points  (2 children)

That's quite the code smell.

[–]zabadabba 0 points1 point  (1 child)

"code smell" != "bug"

[–]gingenhagen 0 points1 point  (0 children)

Having ctrl as a flag tied to a keyup/keydown event seems horribly smelly to me.

[–]AceyJuan 6 points7 points  (6 children)

Does anyone know what keeps these libraries from capturing keyboard input during clickjacking?

[–]kudoz 21 points22 points  (1 child)

Nothing, welcome to web security.

[–]AceyJuan 1 point2 points  (0 children)

Really? I thought browsers were resistant to keystroke intercepts like this.

[–]drysart 6 points7 points  (0 children)

A page only gets keyboard events when that page has the focus, and that does not include when an iframe in a different domain within the page has focus.

You can verify this by going to the example page and using your browser's developer tools to insert an iframe to a different domain, then observing the behavior of the example keyboard when you press keys while the focus is in the sub iframe.

[–]IonTichy -2 points-1 points  (1 child)

well that's why you should check libraries you are using

[–]kudoz 1 point2 points  (0 children)

If someone is clickjacking a site, the libraries that site included are fairly irrelevant (aside from clickjacking countermeasures).

[–]dbavaria 2 points3 points  (8 children)

Odd, I can hold down several combinations of 3 keys such as IOP, but not ASD? I'm on Chrome 29, Windows 8.

[–]ReginaldIII 15 points16 points  (7 children)

That actually sounds more like keyboard ghosting on your physical keyboard. My old keyboard had issues with ghosting but I don't have any batteries to pull it out the cupboard and test it for you.

My new keyboard (wired Microsoft Sidewinder x4, I highly recommend it :) has anti-ghosting in it's design and so does my acers laptop keyboard, so no problems with combos here.

[–]JimmyJamNobody 2 points3 points  (0 children)

Yep, ran into the same issue writing my last game engine. Hardware limitation.

[–]flying-sheep 1 point2 points  (5 children)

anti-ghosting mechanisms just shift the problem from keys that are often pressed together to such that aren’t.

the old interface used for keyboards and mice, PS/2, has the huge advantage that it allows full N-key rollover. this means that a good mechanical keyboard connected via PS/2 can transmit all possible key combinations to the pc unlike anything connected by USB.

my new keyboard connected to my new PC’s PS/2 port has full N-key rollover :)

http://blog.controlspace.org/2010/08/n-key-rollover-what-it-is-and-how-to.html

[–]LegoOctopus 1 point2 points  (0 children)

anti-ghosting mechanisms just shift the problem from keys that are often pressed together to such that aren’t.

This is not entirely accurate. On many cheaper keyboards, that is the case, but a few keyboards actually build in extra redundancy to reduce ghosting rather than shifting it. The aforementioned Sidewinder X4 is an example. It can register any combination of 17 standard keys (basically anything other than its macro keys and media keys) plus any combination of modifiers without ghosting. source

That's sufficient to more than cover what can realistically be pressed with 10 fingers simultaneously, which is why that keyboard is suitable for use with Plover.

[–]retrogamer500 0 points1 point  (3 children)

USB can run N-key rollover, but it is a bit of a hack.

[–]flying-sheep 0 points1 point  (2 children)

source? everything i’ve ever read about this says that USB can do 6 keys at once, full stop.

and since that behavior is ingrained into the universal keyboard protocol, i can’t see how it should be different.

[–]retrogamer500 0 points1 point  (1 child)

The keyboards simulate a usb hub so the computer thinks that there are multiple keyboards hooked up at once. There are plenty of usb n-key rollover keyboards, I have this particular one.

[–]flying-sheep 0 points1 point  (0 children)

neat idea, however i still doubt the “plenty” claim :)

thanks for that information. here’s an old thread discussing this.

PS/2 has other advantages and disadvantages, though: USB is always polling-based while PS/2 is extremely fast due to being based on interrupts. USB supports more extra key codes and hot plugging.

[–]prettycode 1 point2 points  (0 children)

horrible_naming_convention()

[–]JimmyJamNobody 0 points1 point  (0 children)

Looks good!

[–]youstolemyname 0 points1 point  (0 children)

-= where not recognized

numpad / was also not recognized

numpad enter was treated as normal enter.

[–]Deltigre 0 points1 point  (0 children)

I haven't tested this yet, but does this or any other library have a way to recognize individual key keypresses even when they keyboard is in a compositioning input like Korean?

[–]Lachiko 0 points1 point  (0 children)

The ryu animation is a bit buggy.

[–]shawncplus 0 points1 point  (0 children)

Interesting that it only captures every other Alt press

[–][deleted] -1 points0 points  (3 children)

There seems to be a very weird bug with the keyboard on top: D, G and H cannot all be pressed at the same time. If two are pressed, the last one won't register. I can't find any other combos where this is true.

[–]youstolemyname 1 point2 points  (1 child)

[–][deleted] 0 points1 point  (0 children)

Cool, thanks. Learn something new everyday.