20个用来处理键盘事件的JavaScript库

jopen 11年前

Keypress

Keypress is an input capture library with some very special features, it is easy to pick up and use, has a reasonable footprint (~9kb), and has no dependencies. This library have been tested with all major browsers and operating systems, but have not been thoroughly tested in non-English keyboards.





Mousetrap

Mousetrap is a standalone library with no external dependencies. It weighs in at around 1.9kb minified and gzipped and 3.5kb minified. To use any of Mousetrap  extensions all you have to do is include the javascript on your page after you include Mousetrap.
Mousetrap has been tested and should work in Internet Explorer 6+, Safari, Firefox and Chrome.





jQuery Hotkeys
jQuery Hotkeys is a plug-in that lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination. It is known to be working with all the major browsers on all available platforms (Win/Mac/Linux): IE 6/7/8, FF 1.5/2/3, Opera-9, Safari-3 and Chrome-0.2.





Keymage

Keymage is a small library for handling key bindings in JavaScript. It was written out of the fact that no other library supported combination of all necessary features and their design made it easier to write a new one.





KeyboardJS

KeyboardJS is a JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts. It can be used as both a standalone library or an AMD module. The library has support for both single + combo strokes and can work with keyboards of any locale.





kbNav

kbNav can easily make any website completely navigable by keyboard in an intuitive and user-friendly way. kbNav shortcuts appear on the objects you're clicking. You can easily find the shortcut you need. You'll develop an unconscious association between the shortcut and the action while using the site, eliminating the need for memorization.
kbNav shortcuts are activated simply by pressing keys and then hitting enter. Shortcuts can consist of multiple letters/numbers, so every action can have a shortcut.





Keymaster.js

Keymaster is a simple micro-library for defining and dispatching keyboard shortcuts in web applications. Keymaster has no dependencies and can be used completely standalone. It should not interfere with any JavaScript libraries or frameworks.
Keymaster should work with any browser that fires keyup and keydown events, and is tested with IE (6+), Safari, Firefox and Chrome.





Jwerty

jwerty is a JS lib which allows you to bind, fire and assert key combination strings against elements and events. It normalises the poor std api into something easy to use and clear. It weighs around 1.5kb bytes minified and gzipped (~3kb minified) and has no dependencies, but is compatible with jQuery, Zepto or Ender if you include those packages alongside it. 





KeyCode.js

This is a library for normalizing JavaScript key codes across browsers. This library works with key objects, which are { Int code, bool shift, bool alt, bool ctrl } JavaScript objects that record the key code along with any modifiers pressed. translate_event() returns one of these; hot_key() takes one of these and returns a string suitable for the JQuery HotKey plugin or Binny V A's shortcut.js library.





Handling Keyboard Shortcuts in JavaScript

With this library, you can add keyboard shortcuts to your JavaScript app. It support Meta Key for Mac, and beware that it's beta - so expect some problems.





keyboard.backbone.js

keyboard.backbone.js depends on domEvents.backbone.js, which in turn depends on jQuery and Backbone. There's no particular reason for the dependency on domEvents, apart from the fact that keyboard.backbone.js only binds on keyDown and keyUp (well, key:down and key:up), so if you want to take a different action on key:press, you're going to need a different library for it.





Kibo

Kibo is a simple JavaScript library for handling keyboard events. Kibo has no dependencies and it's released under the MIT License.





JavaScript Shortcuts Library

This is an impressive, yet easy-to-use JavaScript shortcut library for handling keyboard events.





User Keyboard Shortcuts

UserKeyboardShortcuts is a refactor of the Keyboard class provided by mootools-more. It makes it easy for you to provide local user-customizable keyboard shortcuts for your users that you don't have to care about.

You just use Keyboard.addShortcuts (provided by Keyboard.Extras) as you usually would, then the user can change the keys to their liking. The assignments they make will be stored using localStorage (failing that a cookie) and will be restored on each subsequent page load.





okShortcut

The two methods jQuery.shortcut.add and jQuery.shortcut.remove are used to add and remove key bindings, respectively. Both take a key-combination and a callback. jQuery.shortcut.add can optionally receive an options hash.





jQuery Beeline

Beeline means take the most direct route. It's keyboard navigation for web applications, and it's base upon jQuery Hotkeys.





jQuery Shortcuts

jQuery Shortcuts is a very lightweight approach to keyboard shortcuts (hotkeys) with jQuery, and it's licensed under the MIT and GPL licenses.





KEY-BOARD-SHORT-CUTS

A simple example of key boards shortcuts implementation with JavaScript. It has no intention to be a complex implementation of binding JavaScript events. All the actions after the bind keys recognized, stay with the programmer creativity.





jKey

jKey is another useful JavaScript shortcut library for handling keyboard events. It works with jQuery, so you can select any applicable element to set a key command to. Basically, any element that can be focused on such as an input or textarea can have a key command applied to it.





Keys.js

Keys.js is a great keybindings for browser applications. It serialize bindings for persistance using localStorage, or uploading to a server for personalized keybindings in your web application. Deserialize them easily using the same API.
Key.js has CommonJS and AMD module support, and can be used with require.js or another module loader, and it has been tested on browsers like: IE7+, Firefox 21+, Safari 6+ and Chrome 27+.