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

Implement key.name for SDL2 #620

Merged
merged 2 commits into from
Nov 14, 2018
Merged

Implement key.name for SDL2 #620

merged 2 commits into from
Nov 14, 2018

Conversation

dlon
Copy link
Member

@dlon dlon commented Nov 11, 2018

  • Switch from using scan codes to (mostly) key codes.
  • Implement key.name() for SDL2.
  • For backward compatibility, use old strings (from SDL1) where possible. It may not cover unusual cases (some constants were removed).

Closes #533.

Questions

  • Is there any reason not to use key codes instead of scan codes?
  • Should the scan code constants added to .constants be kept?

@Farbfetzen
Copy link
Contributor

I admit I don't fully understand the difference between keycodes and scancodes. But doesn't removing scancodes make it more annying/harder to write games for non-us keyboard layouts?

@dlon
Copy link
Member Author

dlon commented Nov 11, 2018

@BastiHz Good point.

Did pygame < 2 use scancodes? If so, I wonder why key events had a "scancode" field as well as a "key" field. If it didn't, should it not continue to use key codes and add scancodes separately?

@illume
Copy link
Member

illume commented Nov 14, 2018

The SDL migration guide has a section on input:
https://wiki.libsdl.org/MigrationGuide#Input

There are these sections in the wiki.
https://wiki.libsdl.org/SDL_KeyboardEvent
https://wiki.libsdl.org/SDL_TextInputEvent
https://wiki.libsdl.org/SDL_TextEditingEvent

There is also this event: SDL_KEYMAPCHANGED which "keymap changed due to a system event such as an input language or keyboard layout change (>= SDL 2.0.4)".

What do you think about starting to add relevant documentation URLs to each of the modules or functions?

Related to this is this issue about SDL_TEXTINPUT:
#623

@illume
Copy link
Member

illume commented Nov 14, 2018

Scancodes are useful when you want to use the position on the keyboard. But not what the letter is.
eg. Where Z is on a US keyboard, is where Y is on a German one.

Scancode == z, means on a German keyboard it will press where the Y key is. (theoretically, there are some weird things on some keyboards... but mostly this will be true).

To answer the question: Using key codes seems the best way to go for backwards compatibility. (there is the scancode on the event for people who want to use that) Using SDL_TEXTINPUT seems the best way going forward, to be able to handle all text input properly.

I think we should merge this?

@dlon dlon merged commit 2fa1930 into pygame:master Nov 14, 2018
dlon added a commit to dlon/pygame that referenced this pull request Nov 15, 2018
@dlon dlon added the 2.0 label Nov 15, 2018
@dlon dlon deleted the key-names branch December 15, 2018 21:17
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.

3 participants