@@ -20,19 +20,19 @@ var SnapFloor = require('../../math/snap/SnapFloor');
2020/**
2121 * @classdesc
2222 * The Keyboard Plugin is an input plugin that belongs to the Scene-owned Input system.
23- *
23+ *
2424 * Its role is to listen for native DOM Keyboard Events and then process them.
25- *
25+ *
2626 * You do not need to create this class directly, the Input system will create an instance of it automatically.
27- *
27+ *
2828 * You can access it from within a Scene using `this.input.keyboard`. For example, you can do:
2929 *
3030 * ```javascript
3131 * this.input.keyboard.on('keydown', callback, context);
3232 * ```
3333 *
3434 * Or, to listen for a specific key:
35- *
35+ *
3636 * ```javascript
3737 * this.input.keyboard.on('keydown-A', callback, context);
3838 * ```
@@ -42,7 +42,7 @@ var SnapFloor = require('../../math/snap/SnapFloor');
4242 * ```javascript
4343 * var spaceBar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
4444 * ```
45- *
45+ *
4646 * If you have multiple parallel Scenes, each trying to get keyboard input, be sure to disable capture on them to stop them from
4747 * stealing input from another Scene in the list. You can do this with `this.input.keyboard.enabled = false` within the
4848 * Scene to stop all input, or `this.input.keyboard.preventDefault = false` to stop a Scene halting input on another Scene.
@@ -218,35 +218,35 @@ var KeyboardPlugin = new Class({
218218 *
219219 * This `addCapture` method enables consuming keyboard events for specific keys, so they don't bubble up the browser
220220 * and cause the default behaviors.
221- *
221+ *
222222 * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to say prevent
223223 * the SPACE BAR from triggering a page scroll, then it will prevent it for any Scene in your game, not just the calling one.
224- *
224+ *
225225 * You can pass a single key code value:
226- *
226+ *
227227 * ```javascript
228228 * this.input.keyboard.addCapture(62);
229229 * ```
230- *
230+ *
231231 * An array of key codes:
232- *
232+ *
233233 * ```javascript
234234 * this.input.keyboard.addCapture([ 62, 63, 64 ]);
235235 * ```
236- *
236+ *
237237 * Or, a comma-delimited string:
238- *
238+ *
239239 * ```javascript
240240 * this.input.keyboard.addCapture('W,S,A,D');
241241 * ```
242- *
242+ *
243243 * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'.
244- *
244+ *
245245 * You can also provide an array mixing both strings and key code integers.
246246 *
247247 * @method Phaser.Input.Keyboard.KeyboardPlugin#addCapture
248248 * @since 3.16.0
249- *
249+ *
250250 * @param {(string|integer|integer[]|any[]) } keycode - The Key Codes to enable event capture for.
251251 *
252252 * @return {this } This KeyboardPlugin object.
@@ -260,35 +260,35 @@ var KeyboardPlugin = new Class({
260260
261261 /**
262262 * Removes an existing key capture.
263- *
263+ *
264264 * Please note that keyboard captures are global. This means that if you call this method from within a Scene, to remove
265265 * the capture of a key, then it will remove it for any Scene in your game, not just the calling one.
266- *
266+ *
267267 * You can pass a single key code value:
268- *
268+ *
269269 * ```javascript
270270 * this.input.keyboard.removeCapture(62);
271271 * ```
272- *
272+ *
273273 * An array of key codes:
274- *
274+ *
275275 * ```javascript
276276 * this.input.keyboard.removeCapture([ 62, 63, 64 ]);
277277 * ```
278- *
278+ *
279279 * Or, a comma-delimited string:
280- *
280+ *
281281 * ```javascript
282282 * this.input.keyboard.removeCapture('W,S,A,D');
283283 * ```
284- *
284+ *
285285 * To use non-alpha numeric keys, use a string, such as 'UP', 'SPACE' or 'LEFT'.
286- *
286+ *
287287 * You can also provide an array mixing both strings and key code integers.
288288 *
289289 * @method Phaser.Input.Keyboard.KeyboardPlugin#removeCapture
290290 * @since 3.16.0
291- *
291+ *
292292 * @param {(string|integer|integer[]|any[]) } keycode - The Key Codes to disable event capture for.
293293 *
294294 * @return {this } This KeyboardPlugin object.
@@ -305,7 +305,7 @@ var KeyboardPlugin = new Class({
305305 *
306306 * @method Phaser.Input.Keyboard.KeyboardPlugin#getCaptures
307307 * @since 3.16.0
308- *
308+ *
309309 * @return {integer[] } An array of all the currently capturing key codes.
310310 */
311311 getCaptures : function ( )
@@ -347,7 +347,7 @@ var KeyboardPlugin = new Class({
347347
348348 /**
349349 * Removes all keyboard captures.
350- *
350+ *
351351 * Note that this is a global change. It will clear all event captures across your game, not just for this specific Scene.
352352 *
353353 * @method Phaser.Input.Keyboard.KeyboardPlugin#clearCaptures
@@ -390,11 +390,11 @@ var KeyboardPlugin = new Class({
390390 * ```javascript
391391 * this.input.keyboard.addKeys({ 'up': Phaser.Input.Keyboard.KeyCodes.W, 'down': Phaser.Input.Keyboard.KeyCodes.S });
392392 * ```
393- *
393+ *
394394 * would return an object containing the properties (`up` and `down`) mapped to W and S {@link Phaser.Input.Keyboard.Key} objects.
395395 *
396396 * You can also pass in a comma-separated string:
397- *
397+ *
398398 * ```javascript
399399 * this.input.keyboard.addKeys('W,S,A,D');
400400 * ```
@@ -568,7 +568,7 @@ var KeyboardPlugin = new Class({
568568
569569 /**
570570 * Creates a new KeyCombo.
571- *
571+ *
572572 * A KeyCombo will listen for a specific string of keys from the Keyboard, and when it receives them
573573 * it will emit a `keycombomatch` event from this Keyboard Plugin.
574574 *
@@ -610,24 +610,26 @@ var KeyboardPlugin = new Class({
610610
611611 /**
612612 * Checks if the given Key object is currently being held down.
613- *
613+ *
614614 * The difference between this method and checking the `Key.isDown` property directly is that you can provide
615615 * a duration to this method. For example, if you wanted a key press to fire a bullet, but you only wanted
616616 * it to be able to fire every 100ms, then you can call this method with a `duration` of 100 and it
617617 * will only return `true` every 100ms.
618- *
618+ *
619619 * If the Keyboard Plugin has been disabled, this method will always return `false`.
620620 *
621621 * @method Phaser.Input.Keyboard.KeyboardPlugin#checkDown
622622 * @since 3.11.0
623623 *
624624 * @param {Phaser.Input.Keyboard.Key } key - A Key object.
625625 * @param {number } [duration=0] - The duration which must have elapsed before this Key is considered as being down.
626- *
626+ *
627627 * @return {boolean } `true` if the Key is down within the duration specified, otherwise `false`.
628628 */
629629 checkDown : function ( key , duration )
630630 {
631+ if ( duration === undefined ) { duration = 0 ; }
632+
631633 if ( this . enabled && key . isDown )
632634 {
633635 var t = SnapFloor ( this . time - key . timeDown , duration ) ;
@@ -681,7 +683,7 @@ var KeyboardPlugin = new Class({
681683 {
682684 event . cancelled = 1 ;
683685 } ;
684-
686+
685687 // Won't reach any more handlers in any Scene further down the Scene list
686688 event . stopPropagation = function ( )
687689 {
@@ -760,7 +762,7 @@ var KeyboardPlugin = new Class({
760762 * Resets all Key objects created by _this_ Keyboard Plugin back to their default un-pressed states.
761763 * This can only reset keys created via the `addKey`, `addKeys` or `createCursorKeys` methods.
762764 * If you have created a Key object directly you'll need to reset it yourself.
763- *
765+ *
764766 * This method is called automatically when the Keyboard Plugin shuts down, but can be
765767 * invoked directly at any time you require.
766768 *
@@ -787,7 +789,7 @@ var KeyboardPlugin = new Class({
787789
788790 /**
789791 * Shuts this Keyboard Plugin down. This performs the following tasks:
790- *
792+ *
791793 * 1 - Resets all keys created by this Keyboard plugin.
792794 * 2 - Stops and removes the keyboard event listeners.
793795 * 3 - Clears out any pending requests in the queue, without processing them.
0 commit comments