

Keypress: A robust JavaScript library for capturing keyboard input - Exuma
http://dmauro.github.io/Keypress/

======
duncanawoods
A big problem I experience is the lack of web-safe keyboard shortcuts for
complex web-apps. If looking for a safe key-combination, you have to consider
the superset of OS and Browser combinations and that leaves almost nothing.

The gmail approach is for unmodified keys but that only works if you don't
have focus in an editable field. The gdocs approach is for menu chords but
that sucks for frequent actions and still generates weird dual handling of
events by the browser.

I'd love a web/browser standards committee to preserve the universal utility
of the keyboard. It could ring-fence some application specific shortcuts, give
a semantic abstraction of some actions e.g. undo, and standardise mechanisms
for os specific remappings.

As it is, as more tech comes along, the less usable keyboards become. I am
still dumbfounded that the iPad lacks a tab button or any chord for one
despite claiming to be usable for word-processing. This basically means no
web-app can ever assume a keyboard has a tab key. Gah.

~~~
jakub_g
This is especially painful since sometimes browsers have different built-in
shortcuts, and sometimes the in-browser shortcuts differ cross-platform.

Also, coming from Windows/Linux world, I was surprised how many physical keys
are missing on a Mac keyboard.

------
double051
Getting an error on that page in Chrome.

    
    
        Refused to execute script from 'https://rawgithub.com/dmauro/Keypress/master/keypress.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
    

EDIT: It's because Keypress is using rawgit.com instead of cdn.rawgit.com to
host the actual keypress.js script.

Details here -
[http://rawgit.com/dmauro/Keypress/master/keypress.js](http://rawgit.com/dmauro/Keypress/master/keypress.js)

Working script source -
[http://cdn.rawgit.com/dmauro/Keypress/master/keypress.js](http://cdn.rawgit.com/dmauro/Keypress/master/keypress.js)

~~~
dcre
RawGit is refusing to send the page because you're not supposed to use it for
production sites without using the cdn.rawgit.com link.

~~~
pmontra
To be more precise: by looking at the response in Firebug's Net panel I see

<h1>Blacklisted for abuse</h1>

<p> This request has been blacklisted for sending too much traffic to
<code>rawgit.com</code>. Please contact the owner of the site that sent you
here and ask them to use <code>cdn.rawgit.com</code> instead, which has no
traffic limit. </p>

Nevertheless I wonder if this will work when Firefox's search as you type is
enabled. I guess the browser should eat up all those events, but maybe I'm
wrong. Can't check it because of the blacklisted script and no time to write
my own test now.

~~~
evilpie
Seems like they also deliver this with an HTTP 200 status. So Firefox actually
tries to parse the error page as JavaScript.

------
taspeotis
Previous discussion
[https://news.ycombinator.com/item?id=6464138](https://news.ycombinator.com/item?id=6464138)

    
    
        Keypress: A Javascript library for capturing input (dmauro.github.io)
        192 points by nsmalch 468 days ago | flag | cached | share | comments

~~~
franciscop
I thought only one submission per url was possible

~~~
abrowne
Per year, I think.

~~~
bobbykjack
From the FAQ [1]:

"Are reposts ok?

If a story has had significant attention in the last year or so, we kill
reposts as duplicates. If not, a small number of reposts is ok."

As with much of the HN system, that's intentionally vague, but in my
interpretation, reposts can occur more frequently than once per year.

[1]
[https://news.ycombinator.com/newsfaq.html](https://news.ycombinator.com/newsfaq.html)

------
avel
An alternative is mouestrap:
[http://craig.is/killing/mice](http://craig.is/killing/mice)

I've used it successfully in Marionette and Angular applications.

It is 29k unminified, vs 35k of keypress.js.

~~~
skuunk1
Plus one for Mousetrap. I have used it too...

Also, it has a better name. ;)

------
jefftchan
I'd like to see scoping added so it's possible to easily switch keyboard
bindings based on the feature/context.

[https://github.com/madrobby/keymaster](https://github.com/madrobby/keymaster)
does an OK job with this, and too bad it's not being actively maintained.

~~~
dmauro
The first param of the constructor for the Listener is an element to be bound
to so it will only listen for key events for that element.

------
codecurve
More aimed at game developers, but for anyone who wants a super lightweight
subset of this functionality.

[https://github.com/danprince/keystate](https://github.com/danprince/keystate)

------
Tad_Ghostly
Now with Konami code!

