A simple keyboard compatibility layer for jquery. Inspired by jquery.hotkeys
- easy-to-remember key names instead of key codes
- fire a single event so you can use switch for dispatching
- handles key repeats consistently across browsers
- listening on the document ignores key events from text accepting inputs
$(document).keylisten(function(e) {
var dir = null;
switch(e.keyName) {
case "shift+up":
dir = dir || 'top';
case "up":
dir = dir || 'prev';
case "shift+down":
dir = dir || 'bottom';
case "down":
dir = dir || 'next';
move(dir, e);
return false;
case "enter":
case "return":
case "tab":
select(e);
return false;
case "esc":
case "del":
case "backspace":
close();
return false;
default:
refresh();
break;
}
})
See the code for all the keynames.