Browse Source

rename scancode to mappedcode so it does not get confused with the conflicting definitions of scancode in GFLW and SDL.

pull/4481/head
Jeffery Myers 6 days ago
parent
commit
a066d647a8
7 changed files with 22 additions and 18 deletions
  1. +1
    -1
      src/platforms/rcore_android.c
  2. +2
    -1
      src/platforms/rcore_desktop_glfw.c
  3. +1
    -1
      src/platforms/rcore_desktop_rgfw.c
  4. +9
    -6
      src/platforms/rcore_desktop_sdl.c
  5. +4
    -4
      src/platforms/rcore_drm.c
  6. +1
    -1
      src/platforms/rcore_web.c
  7. +4
    -4
      src/rcore.c

+ 1
- 1
src/platforms/rcore_android.c View File

@ -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;

+ 2
- 1
src/platforms/rcore_desktop_glfw.c View File

@ -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++;
}

+ 1
- 1
src/platforms/rcore_desktop_rgfw.c View File

@ -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++;
}

+ 9
- 6
src/platforms/rcore_desktop_sdl.c View File

@ -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;

+ 4
- 4
src/platforms/rcore_drm.c View File

@ -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++;
}

+ 1
- 1
src/platforms/rcore_web.c View File

@ -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++;
}

+ 4
- 4
src/rcore.c View File

@ -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--;
}

Loading…
Cancel
Save