Skip to content

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.

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.

// 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.
@sbc100 sbc100 closed this Jan 3, 2025
@sbc100 sbc100 deleted the keyCode branch January 3, 2025 22:45
@sbc100 sbc100 restored the keyCode branch January 4, 2025 01:16
@sbc100 sbc100 reopened this Jan 4, 2025
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