From 463cf73610d911e8eff95ae345143137cf610be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 26 Jun 2026 16:53:18 +0200 Subject: [PATCH] Win32: Fix scancode for media keys Media key events were incorrectly reported with a scancode of 0x100. This is based on a snippet by dougbinks in #2625. Fixes #1768 Closes #2417 Fixes #2625 --- README.md | 1 + src/win32_window.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 90cf45e7..416de2ad 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ information on what to include when reporting a bug. - Updated minimum CMake version to 3.16 (#2541) - Removed support for building with original MinGW (#2540) - [Win32] Removed support for Windows XP and Vista (#2505) + - [Win32] Bugfix: Media keys were reported with a scancode of 256 (#1768,#2417,#2625) - [Cocoa] Added `QuartzCore` framework as link-time dependency - [Cocoa] Removed support for OS X 10.10 Yosemite and earlier (#2506) - [Cocoa] Bugfix: Cmd+Period, Ctrl+Tab and Ctrl+Esc key events were not emitted diff --git a/src/win32_window.c b/src/win32_window.c index 6427a673..8f83a9a0 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -711,11 +711,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l const int mods = getKeyMods(); scancode = (HIWORD(lParam) & (KF_EXTENDED | 0xff)); - if (!scancode) + if (!(scancode & 0xff)) { - // NOTE: Some synthetic key messages have a scancode of zero - // HACK: Map the virtual key back to a usable scancode - scancode = MapVirtualKeyW((UINT) wParam, MAPVK_VK_TO_VSC); + // NOTE: Both media keys and the synthetic key messages from Windows + // Clipboard History are reported with a scancode of zero + // HACK: Map the virtual key to a scancode but preserve extended bit + scancode |= MapVirtualKeyW((UINT) wParam, MAPVK_VK_TO_VSC); } // HACK: Alt+PrtSc has a different scancode than just PrtSc