From 502d74ee3938eed059e987950dc398500c05ed1e Mon Sep 17 00:00:00 2001 From: photonstorm Date: Mon, 3 Mar 2014 11:18:56 +0000 Subject: [PATCH] Keyboard.event now stores the most recent DOM keyboard event. --- README.md | 1 + src/input/Keyboard.js | 57 ++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index d3d6ad5f..ecb3646a 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ Updates: * RandomDataGenerator.integerInRange(min, max) now includes both `min` and `max` within its range (#501) * Tween no longer copies all the object properties into the `_valuesStart` object on creation. * Completely empty Tilemaps can now be created. This allows for dynamic map generation at runtime. +* Keyboard.event now stores the most recent DOM keyboard event. Bug Fixes: diff --git a/src/input/Keyboard.js b/src/input/Keyboard.js index a738aa5d..f99cd173 100644 --- a/src/input/Keyboard.js +++ b/src/input/Keyboard.js @@ -17,18 +17,6 @@ Phaser.Keyboard = function (game) { * @property {Phaser.Game} game - Local reference to game. */ this.game = game; - - /** - * @property {array} _keys - The array the Phaser.Key objects are stored in. - * @private - */ - this._keys = []; - - /** - * @property {array} _capture - The array the key capture values are stored in. - * @private - */ - this._capture = []; /** * You can disable all Keyboard Input by setting disabled to true. While true all new input related events will be ignored. @@ -38,18 +26,9 @@ Phaser.Keyboard = function (game) { this.disabled = false; /** - * @property {function} _onKeyDown - * @private - * @default + * @property {Object} event - The most recent DOM event. This is updated every time a new key is pressed or released. */ - this._onKeyDown = null; - - /** - * @property {function} _onKeyUp - * @private - * @default - */ - this._onKeyUp = null; + this.event = null; /** * @property {Object} callbackContext - The context under which the callbacks are run. @@ -65,6 +44,32 @@ Phaser.Keyboard = function (game) { * @property {function} onUpCallback - This callback is invoked every time a key is released. */ this.onUpCallback = null; + + /** + * @property {array} _keys - The array the Phaser.Key objects are stored in. + * @private + */ + this._keys = []; + + /** + * @property {array} _capture - The array the key capture values are stored in. + * @private + */ + this._capture = []; + + /** + * @property {function} _onKeyDown + * @private + * @default + */ + this._onKeyDown = null; + + /** + * @property {function} _onKeyUp + * @private + * @default + */ + this._onKeyUp = null; }; @@ -238,6 +243,8 @@ Phaser.Keyboard.prototype = { */ processKeyDown: function (event) { + this.event = event; + if (this.game.input.disabled || this.disabled) { return; @@ -272,6 +279,8 @@ Phaser.Keyboard.prototype = { */ processKeyUp: function (event) { + this.event = event; + if (this.game.input.disabled || this.disabled) { return; @@ -303,6 +312,8 @@ Phaser.Keyboard.prototype = { */ reset: function () { + this.event = null; + var i = this._keys.length; while (i--)