2014-09-19 17:37:10 +02:00
|
|
|
var App = App || {};
|
|
|
|
|
|
|
|
App.Keyboard = function(mousetrap) {
|
|
|
|
|
|
|
|
function keyup(key, callback) {
|
2014-10-18 12:42:29 +02:00
|
|
|
unbind(key);
|
2014-09-19 17:37:10 +02:00
|
|
|
mousetrap.bind(key, simpleKeyPressed(callback), 'keyup');
|
|
|
|
}
|
|
|
|
|
|
|
|
function keydown(key, callback) {
|
2014-10-18 12:42:29 +02:00
|
|
|
unbind(key);
|
2014-09-19 17:37:10 +02:00
|
|
|
mousetrap.bind(key, simpleKeyPressed(callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
function simpleKeyPressed(callback) {
|
|
|
|
return function(e) {
|
|
|
|
if (!e.altKey && !e.ctrlKey) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-09-29 18:11:21 +02:00
|
|
|
function reset() {
|
|
|
|
mousetrap.reset();
|
|
|
|
}
|
|
|
|
|
2014-10-05 10:09:02 +02:00
|
|
|
function unbind(key) {
|
2014-10-18 12:42:29 +02:00
|
|
|
mousetrap.unbind(key, 'keyup');
|
2014-10-05 10:09:02 +02:00
|
|
|
mousetrap.unbind(key);
|
|
|
|
}
|
|
|
|
|
2014-09-19 17:37:10 +02:00
|
|
|
return {
|
|
|
|
keydown: keydown,
|
|
|
|
keyup: keyup,
|
2014-09-29 18:11:21 +02:00
|
|
|
reset: reset,
|
2014-10-05 10:09:02 +02:00
|
|
|
unbind: unbind,
|
2014-09-19 17:37:10 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
App.DI.register('keyboard', ['mousetrap'], App.Keyboard);
|