The KeyboardPlugin will now track the key code and timestamp of the previous key pressed and compare it to the current event. If they match, it will skip the event. On some systems if you were to type quickly, you would sometimes get duplicate key events firing (the exact same event firing more than once). This is now prevented from happening.

This commit is contained in:
Richard Davey 2020-08-01 21:06:42 +01:00
parent c4000843ec
commit 2810396dc7

View file

@ -146,7 +146,24 @@ var KeyboardPlugin = new Class({
*/
this.combos = [];
this.prevCode = 0;
/**
* Internal repeat key flag.
*
* @name Phaser.Input.Keyboard.KeyboardPlugin#prevCode
* @type {string}
* @private
* @since 3.50.0
*/
this.prevCode = null;
/**
* Internal repeat key flag.
*
* @name Phaser.Input.Keyboard.KeyboardPlugin#prevTime
* @type {number}
* @private
* @since 3.50.0
*/
this.prevTime = 0;
sceneInputPlugin.pluginEvents.once(InputEvents.BOOT, this.boot, this);
@ -725,6 +742,16 @@ var KeyboardPlugin = new Class({
continue;
}
// Duplicate event bailout
if (code === this.prevCode && event.timeStamp === this.prevTime)
{
// On some systems, the exact same event will fire multiple times. This prevents it.
continue;
}
this.prevCode = code;
this.prevTime = event.timeStamp;
if (event.type === 'keydown')
{
// Key specific callback first