mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
fixed #97 chuck stops when he shouldnt, also removed f/g for handActionRequestLeft and Right, since we don't need it for DebugDraw anymore.
This commit is contained in:
parent
5f5fec5b10
commit
61e66f5796
3 changed files with 61 additions and 52 deletions
|
|
@ -5,46 +5,46 @@ define([
|
|||
function (Key) {
|
||||
|
||||
function KeyboardInput () {
|
||||
this._registry = {};
|
||||
this.registry = {};
|
||||
this.init();
|
||||
}
|
||||
|
||||
KeyboardInput.prototype.init = function () {
|
||||
// Using window is ok here because it only runs in the browser
|
||||
window.onkeydown = this._onKeyDown.bind(this);
|
||||
window.onkeyup = this._onKeyUp.bind(this);
|
||||
window.onkeydown = this.onKeyDown.bind(this);
|
||||
window.onkeyup = this.onKeyUp.bind(this);
|
||||
}
|
||||
|
||||
KeyboardInput.prototype.registerKey = function (keyCode, onKeyDown, onKeyUp) {
|
||||
var key = new Key();
|
||||
if(onKeyDown) key.setKeyDownFunction(onKeyDown);
|
||||
if(onKeyUp) key.setKeyUpFunction(onKeyUp);
|
||||
this._registry[keyCode] = key;
|
||||
this.registry[keyCode] = key;
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._getKeyByKeyCode = function (keyCode) {
|
||||
return this._registry[keyCode];
|
||||
KeyboardInput.prototype.getKeyByKeyCode = function (keyCode) {
|
||||
return this.registry[keyCode];
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._onKeyDown = function (e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
KeyboardInput.prototype.onKeyDown = function (e) {
|
||||
var key = this.getKeyByKeyCode(e.keyCode);
|
||||
|
||||
if (key && !key.getActive()) {
|
||||
var callback = key.getKeyDownFunction();
|
||||
if(callback) callback();
|
||||
key.setActive(true);
|
||||
if(callback) callback();
|
||||
}
|
||||
|
||||
// Prevent tab from changing focus
|
||||
if(e.keyCode == 9) return false;
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._onKeyUp = function (e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
KeyboardInput.prototype.onKeyUp = function (e) {
|
||||
var key = this.getKeyByKeyCode(e.keyCode);
|
||||
if (key && key.getActive()) {
|
||||
var callback = key.getKeyUpFunction();
|
||||
if(callback) callback();
|
||||
key.setActive(false);
|
||||
if(callback) callback();
|
||||
}
|
||||
|
||||
// Prevent tab from changing focus
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue