From ac166a658b7cacd6e75cbb3c24819cf0b61095cc Mon Sep 17 00:00:00 2001 From: Sara Fiori Date: Wed, 20 Mar 2024 09:24:15 +0000 Subject: [PATCH 1/2] canonicalKeyName(): Add --- src/skulpt-connection/browser-keyboard.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/skulpt-connection/browser-keyboard.ts b/src/skulpt-connection/browser-keyboard.ts index 5554b9147..da2370e81 100644 --- a/src/skulpt-connection/browser-keyboard.ts +++ b/src/skulpt-connection/browser-keyboard.ts @@ -3,6 +3,12 @@ declare let Sk: any; type KeyName = string; +function canonicalKeyName(e: KeyboardEvent): string { + const key = e.key; + //The vm expect LowerCase letters for key_pressed() + return (key.length === 1 && key.match(/[A-Z]/)) ? key.toLowerCase() : key; +} + export class BrowserKeyboard { undrainedKeydownKeys: Array; keyIsDown: Map; @@ -18,13 +24,15 @@ export class BrowserKeyboard { } onKeyDown(e: KeyboardEvent) { - this.keyIsDown.set(e.key, true); - this.undrainedKeydownKeys.push(e.key); + var key = canonicalKeyName(e); + this.keyIsDown.set(key, true); + this.undrainedKeydownKeys.push(key); e.preventDefault(); } onKeyUp(e: KeyboardEvent) { - this.keyIsDown.set(e.key, false); + var key = canonicalKeyName(e); + this.keyIsDown.set(key, false); e.preventDefault(); } From f857bed8d62431568713ce7d87323b06fc035e67 Mon Sep 17 00:00:00 2001 From: Sara Fiori Date: Wed, 20 Mar 2024 09:27:26 +0000 Subject: [PATCH 2/2] Extend existing test with capital letters --- cypress/e2e/keypresses.cy.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/keypresses.cy.ts b/cypress/e2e/keypresses.cy.ts index 83e97fdc8..caeba6642 100644 --- a/cypress/e2e/keypresses.cy.ts +++ b/cypress/e2e/keypresses.cy.ts @@ -22,11 +22,13 @@ context("Keypress handling", () => { cy.pytchSendKeysToProject("a"); cy.pytchStdoutShouldContain("hello\nhello\n"); - cy.pytchSendKeysToApp("a"); + cy.pytchSendKeysToApp("A"); cy.pytchStdoutShouldContain("hello\nhello\nhello\n"); cy.pytchRedStop(); cy.pytchSendKeysToApp("a"); cy.pytchStdoutShouldContain("hello\nhello\nhello\nhello\n"); + cy.pytchSendKeysToApp("A"); + cy.pytchStdoutShouldContain("hello\nhello\nhello\nhello\nhello\n"); }); });