nodePong/client/js/keyboard/event_handler.js

52 lines
903 B
JavaScript
Raw Normal View History

2016-02-13 10:36:12 +11:00
/**
* @file event_handling.js
* @autour frtk@tetalab
*/
NPGClient.evtHandler = {
keysList: {
F1 : 112,
SPACE : 32,
ESC : 27,
ARROW_UP : 38,
ARROW_DOWN : 40,
ENTER : 13,
DELETE : 46,
BACKSPACE : 8,
},
keyState: {},
//
init: function() {
var self = this;
//
self.keyState = {};
for (k in self.keyList) {
self.keyState[self.keysList[k]] = false;
}
//
document.addEventListener('keydown',function(e) {
self.keyState[e.keyCode || e.which] = true;
self.onKeyDown(e);
}, true);
//
document.addEventListener('keyup',function(e){
self.keyState[e.keyCode || e.which] = false;
}, true);
},
//
loginValidKey: function(k) {
return (key >= 48 && key <= 90);
},
//
onKeyDown : function(evt) {
console.log(evt.keyCode);
},
}