Skip to content

Commit 50502cf

Browse files
committed
Added emitOnRepeat boolean
1 parent da0d980 commit 50502cf

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/input/keyboard/KeyboardPlugin.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,14 @@ var KeyboardPlugin = new Class({
435435
*
436436
* @param {(object|string)} keys - An object containing Key Codes, or a comma-separated string.
437437
* @param {boolean} [enableCapture=true] - Automatically call `preventDefault` on the native DOM browser event for the key codes being added.
438+
* @param {boolean} [emitOnRepeat=false] - Controls if the Key will continuously emit a 'down' event while being held down (true), or emit the event just once (false, the default).
438439
*
439440
* @return {object} An object containing Key objects mapped to the input properties.
440441
*/
441-
addKeys: function (keys, enableCapture)
442+
addKeys: function (keys, enableCapture, emitOnRepeat)
442443
{
443444
if (enableCapture === undefined) { enableCapture = true; }
445+
if (emitOnRepeat === undefined) { emitOnRepeat = false; }
444446

445447
var output = {};
446448

@@ -454,15 +456,15 @@ var KeyboardPlugin = new Class({
454456

455457
if (currentKey)
456458
{
457-
output[currentKey] = this.addKey(currentKey);
459+
output[currentKey] = this.addKey(currentKey, enableCapture, emitOnRepeat);
458460
}
459461
}
460462
}
461463
else
462464
{
463465
for (var key in keys)
464466
{
465-
output[key] = this.addKey(keys[key]);
467+
output[key] = this.addKey(keys[key], enableCapture, emitOnRepeat);
466468
}
467469
}
468470

@@ -481,12 +483,14 @@ var KeyboardPlugin = new Class({
481483
*
482484
* @param {(Phaser.Input.Keyboard.Key|string|integer)} key - Either a Key object, a string, such as `A` or `SPACE`, or a key code value.
483485
* @param {boolean} [enableCapture=true] - Automatically call `preventDefault` on the native DOM browser event for the key codes being added.
486+
* @param {boolean} [emitOnRepeat=false] - Controls if the Key will continuously emit a 'down' event while being held down (true), or emit the event just once (false, the default).
484487
*
485488
* @return {Phaser.Input.Keyboard.Key} The newly created Key object, or a reference to it if it already existed in the keys array.
486489
*/
487-
addKey: function (key, enableCapture)
490+
addKey: function (key, enableCapture, emitOnRepeat)
488491
{
489492
if (enableCapture === undefined) { enableCapture = true; }
493+
if (emitOnRepeat === undefined) { emitOnRepeat = false; }
490494

491495
var keys = this.keys;
492496

@@ -508,6 +512,8 @@ var KeyboardPlugin = new Class({
508512
this.addCapture(key.keyCode);
509513
}
510514

515+
key.setEmitOnRepeat(emitOnRepeat);
516+
511517
return key;
512518
}
513519

@@ -524,6 +530,8 @@ var KeyboardPlugin = new Class({
524530
{
525531
this.addCapture(key);
526532
}
533+
534+
keys[key].setEmitOnRepeat(emitOnRepeat);
527535
}
528536

529537
return keys[key];

0 commit comments

Comments
 (0)