jwerty

⌨ Awesome handling of keyboard events

  • 所有者: keithamus/jwerty
  • 平台:
  • 許可證: Other
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

No Longer Actively Maintained

If someone would like to take over maintainence, feel free to get in touch (@keithamus on twitter). I'll happily transfer this over.

jwerty

Awesome handling of keyboard events
http://keithamus.github.io/jwerty/

Gitter

NPM Downloads
Release
Gittip donate button

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, Ender or CanJS if you
include those packages alongside it. You can install jwerty via npm (for
use with Ender) or Bower.

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 binding to a selector and don't need the context, you can ommit it:

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

Calls to jwerty.key return a subscription handle that you can use to disconnect the callback

var h = jwerty.key('ctrl+shift+P', function () { [...] })
h.unbind()

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');

主要指標

概覽
名稱與所有者keithamus/jwerty
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證Other
所有者活动
創建於2011-09-21 22:36:34
推送於2017-11-07 20:29:35
最后一次提交2017-11-07 20:29:34
發布數5
最新版本名稱v0.3.2 (發布於 )
第一版名稱v0.1 (發布於 )
用户参与
星數1.2k
關注者數40
派生數106
提交數56
已啟用問題?
問題數50
打開的問題數27
拉請求數16
打開的拉請求數5
關閉的拉請求數3
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?