keyboard-js

JavaScript Key Binding Library

目前為 2016-09-21 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/23404/148693/keyboard-js.js

作者
creamidea
版本
0.0.1.20160921233653
建立日期
2016-09-21
更新日期
2016-09-21
尺寸
4.4 KB
授權條款
未知

keyboard-js

A little library for keyboard binding. Now, it just supports chrome.

If you want to support more browsers or nodejs platform, just fork it.

Have fun, XD.

Usage

Full list of key values

Try it

Now, you can try it here. (source)

Quickly start

var Keyboard = require('keyboard-js').Keyboard
var keyboard = new Keyboard() // pay more attention: singal instance

// when you hit <kbd>Shift+b</kbd> or <kbd>Shift+e</kbd> will print `> test uk successfully`.
keyboard.registe('uk', function () {
    console.log('test uk successfully.')
}, ["Shift", "b"], ["Shift", "e"])

// start to listen
keyboard.start()

// have fun :)

Attention

Please pay more attention to the key combo. You should avoid the key conflict. For example, if you registe the Shortcut Key: Shift + B, you will be confused when you hit Shift + B in the textarea. So, be careful.

However, you can use API::Keyboard.end() to end when the textarea is focused and use API::Keyboard.start() to restart when it blurs. Also, you can discard the Shortcut Key: Shift + B.

API

Keyboard.start(): start to listen the keypress event
Keyboard.end():  end to listen keypress event and clean some resource
Keyboard.registe(name:String, callback:Function, [key1:String, key2:String,...], ...): registe the keyboard binding
Keyboard.unregiste(name:String): remove the register by name

LICENSE

MIT

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址