From 7fd6278bc6361df3005c8f175e608d5c4d2733d1 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Mon, 12 Dec 2022 10:42:03 +0100 Subject: [PATCH] [server] fixed key press checks Do not test KBD_FLAGS_DOWN, this only indicates key repeat. Check for the absence of KBD_FLAGS_RELEASE --- server/Sample/sfreerdp.c | 12 ++++++------ server/shadow/X11/x11_shadow.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 4bf512de1..e31028738 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -801,7 +801,7 @@ static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code) WLog_DBG(TAG, "Client sent a keyboard event (flags:0x%04" PRIX16 " code:0x%04" PRIX8 ")", flags, code); - if ((flags & KBD_FLAGS_DOWN) && (code == RDP_SCANCODE_KEY_G)) /* 'g' key */ + if (((flags & KBD_FLAGS_RELEASE) == 0) && (code == RDP_SCANCODE_KEY_G)) /* 'g' key */ { if (settings->DesktopWidth != 800) { @@ -822,7 +822,7 @@ static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code) update->DesktopResize(update->context); tcontext->activated = FALSE; } - else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_C) /* 'c' key */ + else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_C) /* 'c' key */ { if (tcontext->debug_channel) { @@ -830,22 +830,22 @@ static BOOL tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code) WTSVirtualChannelWrite(tcontext->debug_channel, (PCHAR) "test2", 5, &written); } } - else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_X) /* 'x' key */ + else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_X) /* 'x' key */ { WINPR_ASSERT(client->Close); client->Close(client); } - else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_R) /* 'r' key */ + else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_R) /* 'r' key */ { tcontext->audin_open = !tcontext->audin_open; } #if defined(CHANNEL_AINPUT_SERVER) - else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_I) /* 'i' key */ + else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_I) /* 'i' key */ { tcontext->ainput_open = !tcontext->ainput_open; } #endif - else if ((flags & KBD_FLAGS_DOWN) && code == RDP_SCANCODE_KEY_S) /* 's' key */ + else if (((flags & KBD_FLAGS_RELEASE) == 0) && code == RDP_SCANCODE_KEY_S) /* 's' key */ { } diff --git a/server/shadow/X11/x11_shadow.c b/server/shadow/X11/x11_shadow.c index dacfa4662..022f940ef 100644 --- a/server/shadow/X11/x11_shadow.c +++ b/server/shadow/X11/x11_shadow.c @@ -237,10 +237,10 @@ static BOOL x11_shadow_input_keyboard_event(rdpShadowSubsystem* subsystem, rdpSh XLockDisplay(x11->display); XTestGrabControl(x11->display, True); - if (flags & KBD_FLAGS_DOWN) - XTestFakeKeyEvent(x11->display, keycode, True, CurrentTime); - else if (flags & KBD_FLAGS_RELEASE) + if (flags & KBD_FLAGS_RELEASE) XTestFakeKeyEvent(x11->display, keycode, False, CurrentTime); + else + XTestFakeKeyEvent(x11->display, keycode, True, CurrentTime); XTestGrabControl(x11->display, False); XFlush(x11->display);