zjm*_*126 29 javascript javascript-events
我想创建一个使用很多键盘事件的bbs论坛,
那么哪个是最好的键盘事件库,
谢谢
Cra*_*aig 33
只是另一个投入混合.我最近发布了一个名为Mousetrap的产品.您可以在http://craig.is/killing/mice上查看示例
Rob*_*rst 12
就像它一样简单
KeyboardJS.on('a', function(){ alert('hello!'); });
Run Code Online (Sandbox Code Playgroud)
但同样灵活
var bindInstance = KeyboardJS.on('ctrl + a, ctrl + b, c', function(event, keysPressedArray, keyComboString){
//you get the event object
console.log('event object', event);
//you get the keys pressed array
console.log('keys pressed', keysPressedArray);
//you get the key combo string
console.log('combo pressed', keyComboString);
console.log('I will fire when \'ctrl + a\' or \'ctrl +b\' or \'c\' is pressed down');
//block event bubble
return false;
}, function(event, keysPressedArray, keyComboString) {
console.log('I will fire on key up');
//block event bubble
return false;
});
Run Code Online (Sandbox Code Playgroud)
你可以通过调用来清除绑定
bindInstance.clear();
Run Code Online (Sandbox Code Playgroud)
您可以使用特定键清除所有绑定
KeyboardJS.clear('a, b');
Run Code Online (Sandbox Code Playgroud)
它的开源,可在Github上获得.它在Ether中是一个全局库或用于RequireJS的AMD模块.
这是一个介绍视频.
在那里,现在不再担心键盘和代码你的应用程序.;)