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

SDL3 key questions answered! #10156

Merged
merged 6 commits into from
Jul 1, 2024
Merged

SDL3 key questions answered! #10156

merged 6 commits into from
Jul 1, 2024

Conversation

slouken
Copy link
Collaborator

@slouken slouken commented Jul 1, 2024

Events will have unmodified keys as keycodes. SDL_HINT_KEYCODE_OPTIONS will allow using French number keycodes and forcing English keycodes for non-latin keyboards as user options, but we'll remove the option for modified keys, because that's something applications would have to code for to handle correctly.

Key names are not related to key layout, and the name for both 'a' and 'A' keycodes is "A". We'll document this.

Separately we'll rename SDLK_[a-z] to SDLK_[A-Z], but leave the values lower case.

The keycode in the event and the layout will be SDLK_LEFT or SDLK_4 when the scancode is SDL_SCANCODE_KP_4, depending on the numlock modifier state.

In addition, this adds non-US layout support on the Emscripten platform. @icculus, I can't build this, so please review and test!

Fixes #10139
Fixes #10150
Affects #3559 in that if you want to get the keycode with modifiers applied for an event, you'll need to call SDL_GetKeyFromScancode(), rather than setting a hint for that.

slouken added 6 commits June 30, 2024 23:37
Made the symbols uppercase for consistency with the other SDLK_* constants, but the values are still lowercase.
This allows the numpad to work as the user expects based on the numlock state. If the application needs to distinguish the keys, it can check to see whether the scancode is a numpad key or not.
@icculus
Copy link
Collaborator

icculus commented Jul 1, 2024

Ship it!

@slouken slouken merged commit 109f268 into libsdl-org:main Jul 1, 2024
39 checks passed
@slouken slouken deleted the keycodes branch July 1, 2024 20:56
@Dragon-Baroque
Copy link
Contributor

I would like to discuss the commit f787790 of two days ago.

Although it broke some code in Exult, it presented a consistent picture of providing a single event.key value for the various mod states of the alphabetic ( but NLS compliant ), numeric ( including numeric keypad ), arrow and page movements, insert, suppress and return keys, that is, the keys essential to any game. It was sensitive to NumLock, that is fine.

Thus Exult received SDLK_4 when I pressed the 4 key either on the main keyboard or on the numlocked numeric keypad, Exult received SDLK_M when I pressed the M key ( right of L on a french keyboard ), whatever mod key I may been holding.

  • So I find somewhat pitiful that you reverted to handling the numeric keypad separately by yesterday's commit b948d14.
  • I have another problem, the single event.key value regardless of the mod keys does not work ( in both commits ) on the main numeric keys on my french keyboard. I get event.key as SDLK_2 when I press the main 2 key, but é when Shift is held ( which is by the way the opposite of the entered characters ). I should get SDLK_2 whether or not Shift is held, correct ? Here is a trace of a ( slightly enhanced ) checkkeys :

When I press unshifted main 2, I get the correct SDLK_2 event.key :

INFO: Key pressed :  raw 0x03, scancode 31 = 2, keycode 0x00000032 = 2, shifted keycode 0x000000E9 = é, modified keycode 0x000000E9 = é,  modifiers: (none)
INFO: INPUT Text (\xc3\xa9): "é"

When I press shifted main 2, I get the unexpected é event.key :

INFO: Key pressed :  raw 0x03, scancode 31 = 2, keycode 0x000000E9 = é, shifted keycode 0x00000032 = 2, modified keycode 0x00000032 = 2,  modifiers: LSHIFT
INFO: INPUT Text (\x32): "2"

In these messages,

  • the shifted keycode come from SDL_GetKeyFromScancode(event->scancode, SDL_KMOD_SHIFT & event->mod),
  • the modified keycode come from SDL_GetKeyFromScancode(event->scancode, event->mod).

If I prevent SDL to handle the french numkeys with SDL_KEYCODE_OPTIONS=none, I get keycode 0x000000E9 = é when I press the main 2 key with or without Shift.

@icculus
Copy link
Collaborator

icculus commented Jul 3, 2024

I moved this comment to #10165, since we can't reopen a merged Pull Request, and are likely to lose this comment if it's not in an open issue/PR.

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.

SDL_Keycode does no longer represent a key SDL3 key questions
3 participants