Phaser.Key = function (game, keycode){ this.game = game; this.enabled = true ; this.event = null ; this.isDown = false ; this.isUp = true ; this.altKey = false ; this.ctrlKey = false ; this.shiftKey = false ; this.timeDown = 0; this.duration = 0; this.timeUp = -2500; this.repeats = 0; this.keyCode = keycode; this.onDown = new Phaser.Signal(); this.onHoldCallback = null ; this.onHoldContext = null ; this.onUp = new Phaser.Signal(); } ; Phaser.Key.prototype = { update: function (){ if (!this.enabled) { return ; } if (this.isDown) { this.duration = this.game.time.now - this.timeDown; this.repeats++ ; if (this.onHoldCallback) { this.onHoldCallback.call(this.onHoldContext, this); } } } , processKeyDown: function (event){ if (!this.enabled) { return ; } this.event = event; if (this.isDown) { return ; } this.altKey = event.altKey; this.ctrlKey = event.ctrlKey; this.shiftKey = event.shiftKey; this.isDown = true ; this.isUp = false ; this.timeDown = this.game.time.now; this.duration = 0; this.repeats = 0; this.onDown.dispatch(this); } , processKeyUp: function (event){ if (!this.enabled) { return ; } this.event = event; if (this.isUp) { return ; } this.isDown = false ; this.isUp = true ; this.timeUp = this.game.time.now; this.duration = this.game.time.now - this.timeDown; this.onUp.dispatch(this); } , reset: function (hard){ if (typeof hard === 'undefined') { hard = true ; } this.isDown = false ; this.isUp = true ; this.timeUp = this.game.time.now; this.duration = 0; this.enabled = true ; if (hard) { this.onDown.removeAll(); this.onUp.removeAll(); this.onHoldCallback = null ; this.onHoldContext = null ; } } , justPressed: function (duration){ if (typeof duration === "undefined") { duration = 50; } return (this.isDown && this.duration < duration); } , justReleased: function (duration){ if (typeof duration === "undefined") { duration = 50; } return (!this.isDown && ((this.game.time.now - this.timeUp) < duration)); } } ; Phaser.Key.prototype.constructor = Phaser.Key;