i want to make a bbs forum that using much Keyboard event ,
so which is the best Keyboard event library,
thanks
i want to make a bbs forum that using much Keyboard event ,
so which is the best Keyboard event library,
thanks
Just another to throw in the mix. I recently released one called Mousetrap. You can check out examples at http://craig.is/killing/mice
Try KeyboardJS
its as simple as
KeyboardJS.on('a', function(){ alert('hello!'); });
yet as flexible as
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;
});
you can clear a binding by calling
bindInstance.clear();
you can clear all binds with specific keys with
KeyboardJS.clear('a, b');
Its open source and available on Github. Its comes in ether a global library or an AMD module for RequireJS.
Here's an introduction video.
There, now stop worrying about the keyboard and code your app. ;)
KEYPRESS is focused on game input and supports any key as a modifier, among other features. It's also pre-packaged for Meteor.
From what I have seen Mousetrap is the only library that let's you specify key sequences rather than combinations. This came in very handy for my application.
Lots of JavaScript libraries come replete with ways of capturing key input and using it to your advantage. It's a good bet that you will be able to find a library to do just that, and nothing else. I don't have a lot of experience there, however.
I've been using Ext for a while now, and their KeyMap class is really easy to work with. Here is a simple example using it.
new Ext.KeyMap(Ext.getDoc(), {
key: 'abc',
alt: true,
handler: function(k, e) {
var t = Ext.getCmp('tabpanel');
switch(k) {
case 65:
t.setActiveTab(0);
break;
case 66:
t.setActiveTab(1);
break;
case 67:
t.setActiveTab(2);
break;
}
},
stopEvent: true
});
This takes class, Ext.TabPanel, and allows the user to push a keyboard key to change tabs, rather than clicking the tabs themselves.
It can, of course, do much more than this. This is a simple example of how it works though.
This one is better if you are starting and if you want to understand how hot-keys work.
https://github.com/UthaiahBollera/HotkeysInJavascriptLibrary