Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce usage of legacy event.keyCode. NFC #22881

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Nov 7, 2024

This change replaced the usage of the legacy keyCode attribute with the preferred key attribute, which also has the advantage of removing some hardcoded constant numbers.

In order to test this change I fixed the test_glfw_get_key_stuck test and added test_sdl_key_test to the interactive tests.

In doing so I noticed and fixed a crash bug that was introduced in #22874.

@sbc100 sbc100 requested a review from kripken November 7, 2024 21:49
@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 7, 2024

I noticed this could be improved while reviewing #22879. Whichever lands first will have to deal with a conflict.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm if relevant interactive tests pass. By my reading of the MDN docs this looks valid.

@@ -553,7 +553,7 @@ var LibrarySDL = {
receiveEvent(event) {
function unpressAllPressedKeys() {
// Un-press all pressed keys: TODO
for (var keyCode of SDL.keyboardMap) {
for (var keyCode of Object.values(SDL.keyboardMap)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the crash fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I see this crash when running the interactive tests.

@@ -313,7 +313,7 @@ if (!ENVIRONMENT_IS_NODE) {
// Only prevent default on backspace/tab because we don't want unexpected navigation.
// Do not prevent default on the rest as we need the keypress event.
function shouldPreventDefault(event) {
if (event.type === 'keydown' && event.keyCode !== 8 /* backspace */ && event.keyCode !== 9 /* tab */) {
if (event.type === 'keydown' && event.key != 'Backspace' && event.key != 'Tab') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW the logic here seems to be the inverse of what the comment says. Shouldn't all the clauses above be ===?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right to me? Comment above says "prevent default on backspace/tab", the if checks "not backspace, not tab" and returns false if so. So it returns true - prevents default - on backspace/tab as described.

@sbc100
Copy link
Collaborator Author

sbc100 commented Nov 7, 2024

I split out the crash fix: #22884

This change replaced the usage of the legacy `keyCode` attribute
with the preferred `key` attribute, which also has the advantage of
removing some hardcoded constant numbers.

In order to test this change I fixed the `test_glfw_get_key_stuck`
test and added `test_sdl_key_test` to the interactive tests.

In doing so I noticed and fixed a crash bug that was introduced in emscripten-core#22874.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants