diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index 5f9bd49c..156ceda1 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -1236,7 +1236,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) CORE.Input.Keyboard.currentKeyState[key] = 1; // Key down CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = key; - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = -1; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = -1; CORE.Input.Keyboard.keyPressedQueueCount++; } else if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_MULTIPLE) CORE.Input.Keyboard.keyRepeatInFrame[key] = 1; diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index 2a12cff2..47715002 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -1804,7 +1804,8 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i { // Add character to the queue CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = key; - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = scancode; + // glfw calls the key value that is mapped to the layout a scancode. + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = scancode; CORE.Input.Keyboard.keyPressedQueueCount++; } diff --git a/src/platforms/rcore_desktop_rgfw.c b/src/platforms/rcore_desktop_rgfw.c index 2d13ac7e..914d34d3 100644 --- a/src/platforms/rcore_desktop_rgfw.c +++ b/src/platforms/rcore_desktop_rgfw.c @@ -999,7 +999,7 @@ void PollInputEvents(void) if ((CORE.Input.Keyboard.currentKeyState[key] == 0) && (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE)) { CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = key; - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = event->keyCode; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = event->keyCode; CORE.Input.Keyboard.keyPressedQueueCount++; } diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index a1ffb7f9..a7f3c2d9 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1477,9 +1477,9 @@ void PollInputEvents(void) { #if defined(PLATFORM_DESKTOP_SDL3) // SDL3 Migration: The following structures have been removed: * SDL_Keysym - KeyboardKey key = ConvertScancodeToKey(event.key.scancode); + KeyboardKey key = ConvertScancodeToKey(event.key.mappedcode); #else - KeyboardKey key = ConvertScancodeToKey(event.key.keysym.scancode); + KeyboardKey key = ConvertScancodeToKey(event.key.keysym.mappedcode); #endif if (key != KEY_NULL) @@ -1487,8 +1487,11 @@ void PollInputEvents(void) // If key was up, add it to the key pressed queue if ((CORE.Input.Keyboard.currentKeyState[key] == 0) && (CORE.Input.Keyboard.keyPressedQueueCount < MAX_KEY_PRESSED_QUEUE)) { - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = key; - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = event.key.keysym.sym; + // SDL calls the physical key value from the hardware a scancode. + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = key; + + // SDL calls the key value that is mapped to the layout a virtual keysym. + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = event.key.keysym.sym; CORE.Input.Keyboard.keyPressedQueueCount++; } @@ -1508,9 +1511,9 @@ void PollInputEvents(void) { #if defined(PLATFORM_DESKTOP_SDL3) - KeyboardKey key = ConvertScancodeToKey(event.key.scancode); + KeyboardKey key = ConvertScancodeToKey(event.key.mappedcode); #else - KeyboardKey key = ConvertScancodeToKey(event.key.keysym.scancode); + KeyboardKey key = ConvertScancodeToKey(event.key.keysym.mappedcode); #endif if (key != KEY_NULL) CORE.Input.Keyboard.currentKeyState[key] = 0; } break; diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index b17b4adb..61f86a91 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -1310,7 +1310,7 @@ static void ProcessKeyboard(void) CORE.Input.Keyboard.currentKeyState[257] = 1; CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = 257; // Add keys pressed into queue - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = -1; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = -1; CORE.Input.Keyboard.keyPressedQueueCount++; } else if (keysBuffer[i] == 0x7f) // raylib KEY_BACKSPACE @@ -1318,7 +1318,7 @@ static void ProcessKeyboard(void) CORE.Input.Keyboard.currentKeyState[259] = 1; CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = 257; // Add keys pressed into queue - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = -1; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = -1; CORE.Input.Keyboard.keyPressedQueueCount++; } else @@ -1331,7 +1331,7 @@ static void ProcessKeyboard(void) else CORE.Input.Keyboard.currentKeyState[(int)keysBuffer[i]] = 1; CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = keysBuffer[i]; // Add keys pressed into queue - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = -1; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = -1; CORE.Input.Keyboard.keyPressedQueueCount++; } } @@ -1624,7 +1624,7 @@ static void PollKeyboardEvents(void) if (CORE.Input.Keyboard.keyPressedQueueCount < MAX_CHAR_PRESSED_QUEUE) { CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = keycode; - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = (int)event.code; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = (int)event.code; CORE.Input.Keyboard.keyPressedQueueCount++; } diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index 5254ac1c..947a55af 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -1500,7 +1500,7 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i { // Add character to the queue CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = key; - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = scancode; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = scancode; CORE.Input.Keyboard.keyPressedQueueCount++; } diff --git a/src/rcore.c b/src/rcore.c index bc0e4984..f6e19f0c 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -268,7 +268,7 @@ __declspec(dllimport) unsigned int __stdcall timeEndPeriod(unsigned int uPeriod) //---------------------------------------------------------------------------------- typedef struct { int x; int y; } Point; typedef struct { unsigned int width; unsigned int height; } Size; -typedef struct { int keycode; int scancode; } KeyInfo; +typedef struct { int keycode; int mappedcode; } KeyInfo; // Core global state context data typedef struct CoreData { @@ -3062,7 +3062,7 @@ void PlayAutomationEvent(AutomationEvent event) { // Add character to the queue CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].keycode = event.params[0]; - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].scancode = -1; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount].mappedcode = -1; CORE.Input.Keyboard.keyPressedQueueCount++; } } @@ -3200,7 +3200,7 @@ int GetKeyPressedPro(int* scanCode) // Get character from the queue head value = CORE.Input.Keyboard.keyPressedQueue[0].keycode; if (scanCode != NULL) - *scanCode = CORE.Input.Keyboard.keyPressedQueue[0].scancode; + *scanCode = CORE.Input.Keyboard.keyPressedQueue[0].mappedcode; // Shift elements 1 step toward the head for (int i = 0; i < (CORE.Input.Keyboard.keyPressedQueueCount - 1); i++) @@ -3208,7 +3208,7 @@ int GetKeyPressedPro(int* scanCode) // Reset last character in the queue CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount - 1].keycode = 0; - CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount - 1].scancode = -1; + CORE.Input.Keyboard.keyPressedQueue[CORE.Input.Keyboard.keyPressedQueueCount - 1].mappedcode = -1; CORE.Input.Keyboard.keyPressedQueueCount--; }