>From 8d685ff821480aabf28973d2f174f47921617c01 Mon Sep 17 00:00:00 2001 From: Remi Thebault Date: Sun, 25 Jan 2015 17:09:58 +0100 Subject: [PATCH 4/4 v2] input: sdl2 win32 ui handles altgr key correctly Linux guest / Windows host had a dead altgr key problem due to Windows mapping of altgr to ctrl-alt. This commit fixes it by sending a fake ctrl-up event to the guest when appropriate. In case of turbo mode, only one fake event is sent. In a windows guest, altgr key still works as usual. Signed-off-by: Remi Thebault --- ui/sdl2.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/ui/sdl2.c b/ui/sdl2.c index 1ad74ba..bba8f4f 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -73,6 +73,12 @@ static SDL_Cursor *guest_sprite; static int scaling_active; static Notifier mouse_mode_notifier; +#if defined(INPUT_NEEDS_ALTGR_FIX) +/* win32 alt-gr handling */ +static bool l_ctrl_down = 0; +static bool r_alt_down = 0; +#endif + static void sdl_update_caption(struct sdl2_state *scon); static struct sdl2_state *get_scon_from_window(uint32_t window_id) @@ -252,11 +258,37 @@ static void sdl_process_key(struct sdl2_state *scon, } else { modifiers_state[ev->keysym.scancode] = 1; } - /* fall though */ - default: - qemu_input_event_send_key_qcode(con, qcode, - ev->type == SDL_KEYDOWN); + break; + } + +#if defined(INPUT_NEEDS_ALTGR_FIX) + /* Windows maps altgr key to l-ctrl + r-alt. + For proper handling in the guest, only r-alt is to be sent. + This is done by sending a fake "ctrl up" event when appropriate. */ + switch (ev->keysym.scancode) { + case SDL_SCANCODE_LCTRL: /* l-ctrl */ + if (!l_ctrl_down && r_alt_down) { + /* fake ctrl up already sent */ + return; + } + l_ctrl_down = (ev->type == SDL_KEYDOWN); + break; + case SDL_SCANCODE_RALT: /* r-alt */ + if (l_ctrl_down && !r_alt_down && + ev->type == SDL_KEYDOWN) { + /* sending fake "ctrl up" event */ + qemu_input_event_send_key_qcode(con, + sdl2_scancode_to_qcode[SDL_SCANCODE_LCTRL], + false); + l_ctrl_down = false; + } + r_alt_down = (ev->type == SDL_KEYDOWN); + break; } +#endif + + qemu_input_event_send_key_qcode(con, qcode, + ev->type == SDL_KEYDOWN); } static void sdl_update_caption(struct sdl2_state *scon) -- 1.8.5.2.msysgit.0