Skip to content

Commit

Permalink
rename scancode to mappedcode so it does not get confused with the co…
Browse files Browse the repository at this point in the history
…nflicting definitions of scancode in GFLW and SDL.
  • Loading branch information
JeffM2501 committed Dec 12, 2024
1 parent dccef93 commit a066d64
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/platforms/rcore_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/rcore_desktop_glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/rcore_desktop_rgfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
15 changes: 9 additions & 6 deletions src/platforms/rcore_desktop_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1477,18 +1477,21 @@ 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)
{
// 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++;
}

Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/platforms/rcore_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1310,15 +1310,15 @@ 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
{
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
Expand All @@ -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++;
}
}
Expand Down Expand Up @@ -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++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/rcore_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
8 changes: 4 additions & 4 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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++;
}
}
Expand Down Expand Up @@ -3200,15 +3200,15 @@ 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++)
CORE.Input.Keyboard.keyPressedQueue[i] = CORE.Input.Keyboard.keyPressedQueue[i + 1];

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

Expand Down

0 comments on commit a066d64

Please sign in to comment.