πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Sign inDemoInstall
Socket

jwerty

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwerty

Awesome handling of keyboard events

0.3.2
latest
npm
Version published
Weekly downloads
29K
-9.52%
Maintainers
1
Weekly downloads
Β 
Created
Source

jwerty

Awesome handling of keyboard events
http://keithcirkel.co.uk/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.

jwerty is a small library, weighing in at around 1.5kb bytes minified and gzipped (~3kb minified). jwerty has no dependencies, but is compatible with jQuery, Zepto or Ender if you include those packages alongside it.

For detailed docs, please read the README-DETAILED.md file.

The Short version

Use jwerty.key to bind your callback to a key combo (global shortcuts)

jwerty.key('ctrl+shift+P', function () { [...] });
jwerty.key('βŒƒ+⇧+P', function () { [...] });

Specify optional keys...

jwerty.key('βŒƒ+⇧+P/⌘+⇧+P', function () { [...] });

or key sequences.

jwerty.key('↑,↑,↓,↓,←,β†’,←,β†’,B,A,↩', function () { [...] });

You can also (since 0.3) specify regex-like ranges:

jwerty.key('ctrl+[a-c]', function () { [...] }); // fires for ctrl+a,ctrl+b or ctrl+c

Pass in a context to bind your callback:

jwerty.key('βŒƒ+⇧+P/⌘+⇧+P', function () { [...] }, this);

Pass in a selector to bind a shortcut local to that element

jwerty.key('βŒƒ+⇧+P/⌘+⇧+P', function () { [...] }, this, '#myinput');

Pass in a selector's context, similar to jQuery's $('selector', 'scope')

jwerty.key('βŒƒ+⇧+P/⌘+⇧+P', function () { [...] }, this, 'input.email', '#myForm');

If you're bining to a selector, you can also ommit the function context:

jwerty.key('βŒƒ+⇧+P/⌘+⇧+P', function () { [...] }, 'input.email', '#myForm');

Use jwerty.event as a decorator, to bind events your own way:

$('#myinput').bind('keydown', jwerty.event('βŒƒ+⇧+P/⌘+⇧+P', function () { [...] }));

Use jwerty.is to check a keyCombo against a keyboard event:

function (event) {
    if ( jwerty.is('βŒƒ+⇧+P', event) ) {
        [...]
    }
}

Or use jwerty.fire to send keyboard events to other places:

jwerty.fire('enter', 'input:first-child', '#myForm');

Keywords

key

FAQs

Package last updated on 10 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts