[Bug] Fixing keyboard input repeating indefinitely when meta key is held.
This commit is contained in:
parent
6c2880dc30
commit
2114c9737f
|
@ -349,12 +349,16 @@ export class InputsController {
|
||||||
* Handles the keydown event for the keyboard.
|
* Handles the keydown event for the keyboard.
|
||||||
*
|
*
|
||||||
* @param event The keyboard event.
|
* @param event The keyboard event.
|
||||||
|
*
|
||||||
|
* @remarks On Mac the keyup event for a pressed key is not fired if the meta key is held down. To
|
||||||
|
* insure that that key is not repeatedly input until the user presses it again only emit events
|
||||||
|
* when the meta key is not held.
|
||||||
*/
|
*/
|
||||||
keyboardKeyDown(event): void {
|
keyboardKeyDown(event): void {
|
||||||
this.lastSource = "keyboard";
|
this.lastSource = "keyboard";
|
||||||
this.ensureKeyboardIsInit();
|
this.ensureKeyboardIsInit();
|
||||||
const buttonDown = getButtonWithKeycode(this.getActiveConfig(Device.KEYBOARD), event.keyCode);
|
const buttonDown = getButtonWithKeycode(this.getActiveConfig(Device.KEYBOARD), event.keyCode);
|
||||||
if (buttonDown !== undefined) {
|
if (buttonDown !== undefined && !event.metaKey) {
|
||||||
if (this.buttonLock.includes(buttonDown)) {
|
if (this.buttonLock.includes(buttonDown)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,11 @@ describe("Inputs", () => {
|
||||||
expect(game.inputsHandler.log.length).toBe(5);
|
expect(game.inputsHandler.log.length).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keyboard - test input holding meta key - 0 input", async() => {
|
||||||
|
await game.inputsHandler.pressKeyboardKey(cfg_keyboard_qwerty.deviceMapping.KEY_ARROW_UP, 1, true);
|
||||||
|
expect(game.inputsHandler.log.length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
it("keyboard - test input holding for 200ms - 1 input", async() => {
|
it("keyboard - test input holding for 200ms - 1 input", async() => {
|
||||||
await game.inputsHandler.pressKeyboardKey(cfg_keyboard_qwerty.deviceMapping.KEY_ARROW_UP, 200);
|
await game.inputsHandler.pressKeyboardKey(cfg_keyboard_qwerty.deviceMapping.KEY_ARROW_UP, 200);
|
||||||
expect(game.inputsHandler.log.length).toBe(1);
|
expect(game.inputsHandler.log.length).toBe(1);
|
||||||
|
|
|
@ -48,9 +48,9 @@ export default class InputsHandler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pressKeyboardKey(key: integer, duration: integer): Promise<void> {
|
pressKeyboardKey(key: integer, duration: integer, isMetaPressed: boolean = false): Promise<void> {
|
||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
this.scene.input.keyboard?.emit("keydown", {keyCode: key});
|
this.scene.input.keyboard?.emit("keydown", {keyCode: key, metaKey: isMetaPressed});
|
||||||
await holdOn(duration);
|
await holdOn(duration);
|
||||||
this.scene.input.keyboard?.emit("keyup", {keyCode: key});
|
this.scene.input.keyboard?.emit("keyup", {keyCode: key});
|
||||||
resolve();
|
resolve();
|
||||||
|
|
Loading…
Reference in New Issue