[rcore] Add basic support for scancodes #4481
Open
+479
−431
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently raylib does not expose the scancode data for keyboard input received from the platform. This makes it VERY hard to build keyboard bindings that work with different keyboard mappings and localizations. They KeyboardKey enum is just the physical keys and does not take the keyboard mapping into account. For most game input this is fine, as you want the physical key, but there are use cases where you need local mapping of non-text keys.
GetCharPressed handles the mapping, but only for printable characters.
Any user that wants the 'logical' key that is provided by the keyboard mapping as no way to get this data.
The data was passed to the keyboard input functions of most platforms, but the raylib key system has no place to store it.
In SDL this scancode is the 'virtual key'
This PR adds GetKeyPressedPro that takes an optional scancode to fill out, allowing people to see the localized key for each event.
Platforms that don't provide a scancode set the code to -1.
I don't know if this should go into 5.5 or if we should discuss the API for the future. This is just the smallest possible change to raylib to expose the data that it's currently ignoring. I am just posting this so it doesn't get lost.