SDL: Handle Colemak swapping of CapsLock and Backspace

From 66cb2153cc8c59d0629d1d2ef7da4ed3e03099a3 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 4 Aug 2024 09:56:57 -0700
Subject: [PATCH] Handle Colemak swapping of CapsLock and Backspace

Fixes https://github.com/libsdl-org/SDL/issues/7853
---
 src/video/windows/SDL_windowskeyboard.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index 304f15491a1f7..3ff2afdb38fff 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -108,6 +108,18 @@ void WIN_UpdateKeymap(SDL_bool send_event)
             if (scancode == SDL_SCANCODE_UNKNOWN ||
                 scancode == SDL_SCANCODE_DELETE ||
                 (SDL_GetDefaultKeyFromScancode(scancode, SDL_KMOD_NONE) & SDLK_SCANCODE_MASK)) {
+
+                /* The Colemak mapping swaps Backspace and CapsLock */
+                if (mods[m] == SDL_KMOD_NONE &&
+                    (scancode == SDL_SCANCODE_CAPSLOCK ||
+                     scancode == SDL_SCANCODE_BACKSPACE)) {
+                    vk = LOBYTE(MapVirtualKey(i, MAPVK_VSC_TO_VK));
+                    if (vk == VK_CAPITAL) {
+                        SDL_SetKeymapEntry(keymap, scancode, mods[m], SDLK_CAPSLOCK);
+                    } else if (vk == VK_BACK) {
+                        SDL_SetKeymapEntry(keymap, scancode, mods[m], SDLK_BACKSPACE);
+                    }
+                }
                 continue;
             }