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

Convert physical_keycodes to keycodes in the current keyboard layout #52684

Merged
merged 1 commit into from
Oct 1, 2021

Conversation

Frixuu
Copy link
Contributor

@Frixuu Frixuu commented Sep 14, 2021

As far as I know, there is currently no way to map InputEventKey.physical_keycodes to regular scancodes, using the user's current keyboard layout. This functionality could be used in both the editor and games, providing context-aware button prompts.

This PR aims to explore this topic.

Assumptions

A functional system would take a Key, a Godot enum, in the QWERTY layout. If it is reasonable to provide a Key in the user's current keyboard layout (QWERTZ, Dvorak), it should do so. If it is not (Arabic, Cyrillic scripts), the function should return back the original key. The method should ideally return the same keycode, as it would appear in the handled key-press event.
Note: providing a Unicode symbol for the key is not a goal here.

Platform status

  • Linux
    • On layouts with Latin-1, but not ASCII characters, resulting keys might have no corresponding constant. For example on AZERTY, ' (0x27) will map to ù (0xF9). However, this seems consistent with the keycodes in processed input events, and changing that behaviour is not in the scope of this PR.
  • macOS
    • Uses the same routines as the input handler. While not all keys seem to be mapped, it is consistent with the incoming events.
    • Do Macs know what a Pause key is?
  • Windows
    • To the best of my knowledge, the Windows implementation is the only one that slightly differs from the handled input events. The change is best seen in the case of the AZERTY layout.
      • A physical slash (0x2F) carries a KEY_UNKNOWN, however it gets converted to an exclamation mark (0x21).
      • It maps a period (0x2E) to a colon (0x3A), but the incoming event has a keycode of slash (0x2F).
      • The event contains a backslash (0x5C), but it gets mapped to an asterisk (0x2A).
    • However, given the intended purpose of the proposed function, I would argue that it is not a problem worth solving right now. (it would incur changing other parts of the DisplayServer)

Other

  • Come up with some better names
    • For the purpose of this PR, I have picked keyboard_get_keycode_from_physical. I feel it is a bit too verbose while not conveying the intent of the method very clearly. How could we fix it? What verb would be more appropriate?

@bruvzg bruvzg added this to the 4.0 milestone Sep 14, 2021
@Frixuu Frixuu force-pushed the master branch 9 times, most recently from b6eb528 to b3439ab Compare September 20, 2021 01:29
@Frixuu Frixuu marked this pull request as ready for review September 20, 2021 21:05
@Frixuu Frixuu requested review from a team as code owners September 20, 2021 21:05
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for the detailed overview of assumptions and implementation details!

@akien-mga akien-mga merged commit a7011fa into godotengine:master Oct 1, 2021
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants