From 8b088b39850fb395f5b736c596e00c779daa0628 Mon Sep 17 00:00:00 2001 From: GiM Date: Mon, 17 Feb 2025 07:43:18 +0100 Subject: [PATCH] Fix F10 and Alt+F handling on Windows (#24745) Closes #24744 and should also fix #17819 The change is split into two commits, first one adds F10 handling (it needs to be handled inside `parse_syskeydown_msg_keystroke`, the second one properly handles `Alt+Fn` combinations, this also needs to happen in `parse_syskeydown_msg_keystroke` and is similar to a fragment inside `parse_keydown_msg_keystroke` Release Notes: - Fixes F10 and Alt+Fn handling on windows --- crates/gpui/src/platform/windows/events.rs | 37 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rs index 14b34764ae459026961a8aeb47d77f784cda3a6d..2b24403846eb4ab37fac9161db54c5ab9ce2852a 100644 --- a/crates/gpui/src/platform/windows/events.rs +++ b/crates/gpui/src/platform/windows/events.rs @@ -1201,14 +1201,23 @@ fn handle_system_theme_changed( fn parse_syskeydown_msg_keystroke(wparam: WPARAM) -> Option { let modifiers = current_modifiers(); + let vk_code = wparam.loword(); + + // on Windows, F10 can trigger this event, not just the alt key, + // so when F10 was pressed, handle only it if !modifiers.alt { - // on Windows, F10 can trigger this event, not just the alt key - // and we just don't care about F10 - return None; + if vk_code == VK_F10.0 { + let offset = vk_code - VK_F1.0; + return Some(Keystroke { + modifiers, + key: format!("f{}", offset + 1), + key_char: None, + }); + } else { + return None; + } } - let vk_code = wparam.loword(); - let key = match VIRTUAL_KEY(vk_code) { VK_BACK => "backspace", VK_RETURN => "enter", @@ -1226,7 +1235,23 @@ fn parse_syskeydown_msg_keystroke(wparam: WPARAM) -> Option { VK_ESCAPE => "escape", VK_INSERT => "insert", VK_DELETE => "delete", - _ => return basic_vkcode_to_string(vk_code, modifiers), + _ => { + let basic_key = basic_vkcode_to_string(vk_code, modifiers); + if basic_key.is_some() { + return basic_key; + } else { + if vk_code >= VK_F1.0 && vk_code <= VK_F24.0 { + let offset = vk_code - VK_F1.0; + return Some(Keystroke { + modifiers, + key: format!("f{}", offset + 1), + key_char: None, + }); + } else { + return None; + } + } + } } .to_owned();