News for hackers. Stuff that matters.
Re:Keymaster.js: painless keyboard shortcuts for javascript by TrevorBurnham on Sunday August 28, 2011 @10:35AM (#2933986)
Hmm. Binds all events to `document`, which means that if you type something in a text field, it'll still trigger the event. (One of the TODOs is "Make behavior with INPUT / SELECT / TEXTAREA configurable.)

Thing is, jQuery Hotkeys (https://github.com/jeresig/jquery.hotkeys) is more versatile (since you can bind events to any element), works under a wider range of browsers, and is nearly as lightweight (if you already depend on jQuery).

Though, I do like the hipness of using "⌥" and "⌘" instead of "alt" and "meta". I might make a fork of jQuery Hotkeys just for that.

Re:Keymaster.js: painless keyboard shortcuts for javascript by madrobby on Sunday August 28, 2011 @10:56AM (#2934021)
It doesn't trigger events if you're in a INPUT/TEXTAREA/SELECT.

The todo refers to making this configurable in a per-shortcut fashion.

Re:Keymaster.js: painless keyboard shortcuts for javascript by TrevorBurnham on Sunday August 28, 2011 @12:52PM (#2934299)
Ah, my bad. I didn't catch the line "if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA') return;", which is indeed a sensible default.
Re:Keymaster.js: painless keyboard shortcuts for javascript by fbnt on Sunday August 28, 2011 @11:39AM (#2934111)
I recently had the need of using multiple hotkeys for a web application I'm building.

I tried jQuery hotkeys but I had to drop it for a number of reasons: First of all is the unbind problem (well documented on their bug-tracker), if you bind N different keys combination, the callback function for each hotkey is called N times, and that's really annoying and there are no easy workaround. Other than that, not all keys combination are supported, some keys just doesen't work, and it also bind keys per value instead of code: it's basically designed for american keyboards only, the same key value might have different key-codes for different keyboard layouts.

So I came up with a simple homemade solution that words flawlessly for my needs: http://jsfiddle.net/2Saj8/

I'm looking forward to try out keymaster.js though.

Re:Keymaster.js: painless keyboard shortcuts for javascript by TrevorBurnham on Monday September 05, 2011 @08:15PM (#2963665)
In case anyone wants it, here's my unicode-friendly fork of jQuery Hotkeys: https://github.com/TrevorBurnham/jquery.hotkeys

Note that because of the way the library works, you can only use the unicode equivalents on this fork—aliases like "ctrl" and "alt" will not work. (jQuery Hotkeys was written with a pretty hardcore approach to efficiency, so everything is 1:1. Keymaster uses an `indexOf` search each time a key is pressed, which has a negligible impact on performance in modern browsers.)

Re:Keymaster.js: painless keyboard shortcuts for javascript by maratd on Sunday August 28, 2011 @11:01AM (#2934034)
We don't use Keymaster, but our homebrew solution works the same way. You can solve the problem by adding an event to elements that you don't want to react that stops bubbling. Since those elements are focused when a key is pressed, the event for that element will be triggered first. Our form validation script adds this automatically. Problem solved.