clients: use rdp scancode definitions when sending key events
This also introduces a slightly more high-level convenience function for sending key events. The existing function where an RDP protocol flag field has to be encoded by the caller is very lowlevel ... and a bad fit for fastpath input. That could use a refactoring.
This commit is contained in:
parent
7f399c6020
commit
3e4b434925
@ -190,10 +190,7 @@ void df_send_mouse_wheel_event(rdpInput* input, sint16 axisrel, uint16 x, uint16
|
||||
|
||||
void df_send_keyboard_event(rdpInput* input, boolean down, uint8 keycode, uint8 function)
|
||||
{
|
||||
uint16 flags;
|
||||
uint8 vkcode;
|
||||
uint8 scancode;
|
||||
boolean extended;
|
||||
RDP_SCANCODE rdp_scancode;
|
||||
|
||||
if (keycode)
|
||||
@ -204,13 +201,8 @@ void df_send_keyboard_event(rdpInput* input, boolean down, uint8 keycode, uint8
|
||||
return;
|
||||
|
||||
rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_virtual_key_code(vkcode);
|
||||
scancode = rdp_scancode_code(rdp_scancode);
|
||||
extended = rdp_scancode_extended(rdp_scancode);
|
||||
|
||||
flags = (extended) ? KBD_FLAGS_EXTENDED : 0;
|
||||
flags |= (down) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE;
|
||||
|
||||
input->KeyboardEvent(input, flags, scancode);
|
||||
freerdp_input_send_keyboard_event_2(input, down, rdp_scancode);
|
||||
}
|
||||
|
||||
boolean df_event_process(freerdp* instance, DFBEvent* event)
|
||||
|
@ -33,11 +33,9 @@ extern HCURSOR g_default_cursor;
|
||||
|
||||
LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
DWORD flags;
|
||||
wfInfo* wfi;
|
||||
uint8 scanCode;
|
||||
RDP_SCANCODE rdp_scancode;
|
||||
rdpInput* input;
|
||||
uint16 kbdFlags;
|
||||
PKBDLLHOOKSTRUCT p;
|
||||
|
||||
DEBUG_KBD("Low-level keyboard hook, hWnd %X nCode %X wParam %X", g_focus_hWnd, nCode, wParam);
|
||||
@ -52,13 +50,11 @@ LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
case WM_SYSKEYUP:
|
||||
wfi = (wfInfo*) GetWindowLongPtr(g_focus_hWnd, GWLP_USERDATA);
|
||||
p = (PKBDLLHOOKSTRUCT) lParam;
|
||||
scanCode = (uint8) p->scanCode;
|
||||
input = wfi->instance->input;
|
||||
flags = p->flags;
|
||||
kbdFlags = 0;
|
||||
rdp_scancode = mk_rdp_scancode((uint8) p->scanCode, p->flags & LLKHF_EXTENDED);
|
||||
|
||||
DEBUG_KBD("keydown %d scanCode %04X flags %02X vkCode %02X",
|
||||
(wParam == WM_KEYDOWN), scanCode, flags, p->vkCode);
|
||||
(wParam == WM_KEYDOWN), (uint8) p->scanCode, p->flags, p->vkCode);
|
||||
|
||||
if (wfi->fs_toggle &&
|
||||
((p->vkCode == VK_RETURN) || (p->vkCode == VK_CANCEL)) &&
|
||||
@ -70,25 +66,23 @@ LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (scanCode == 0x45) /* NumLock-ish */
|
||||
{
|
||||
if (flags & LLKHF_EXTENDED)
|
||||
if (rdp_scancode == RDP_SCANCODE_NUMLOCK_EXTENDED)
|
||||
{
|
||||
/* Windows sends NumLock as extended - rdp doesn't */
|
||||
DEBUG_KBD("hack: NumLock (x45) should not be extended");
|
||||
flags &= ~LLKHF_EXTENDED;
|
||||
rdp_scancode = RDP_SCANCODE_NUMLOCK;
|
||||
}
|
||||
else
|
||||
else if (rdp_scancode == RDP_SCANCODE_NUMLOCK)
|
||||
{
|
||||
/* Windows sends Pause as if it was a RDP NumLock (handled above).
|
||||
* It must however be sent as a one-shot Ctrl+NumLock */
|
||||
if (wParam == WM_KEYDOWN)
|
||||
{
|
||||
DEBUG_KBD("Pause, sent as Ctrl+NumLock");
|
||||
input->KeyboardEvent(input, KBD_FLAGS_DOWN, 0x1D); /* Ctrl down */
|
||||
input->KeyboardEvent(input, KBD_FLAGS_DOWN, 0x45); /* NumLock down */
|
||||
input->KeyboardEvent(input, KBD_FLAGS_RELEASE, 0x1D); /* Ctrl up */
|
||||
input->KeyboardEvent(input, KBD_FLAGS_RELEASE, 0x45); /* NumLock up */
|
||||
freerdp_input_send_keyboard_event_2(input, true, RDP_SCANCODE_LCONTROL);
|
||||
freerdp_input_send_keyboard_event_2(input, true, RDP_SCANCODE_NUMLOCK);
|
||||
freerdp_input_send_keyboard_event_2(input, false, RDP_SCANCODE_LCONTROL);
|
||||
freerdp_input_send_keyboard_event_2(input, false, RDP_SCANCODE_NUMLOCK);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -97,17 +91,13 @@ LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((scanCode == 0x36) && (flags & LLKHF_EXTENDED))
|
||||
else if (rdp_scancode == RDP_SCANCODE_RSHIFT_EXTENDED)
|
||||
{
|
||||
DEBUG_KBD("hack: right shift (x36) should not be extended");
|
||||
flags &= ~LLKHF_EXTENDED;
|
||||
DEBUG_KBD("right shift (x36) should not be extended");
|
||||
rdp_scancode = RDP_SCANCODE_RSHIFT;
|
||||
}
|
||||
|
||||
kbdFlags |= (flags & LLKHF_UP) ? KBD_FLAGS_RELEASE : KBD_FLAGS_DOWN;
|
||||
kbdFlags |= (flags & LLKHF_EXTENDED) ? KBD_FLAGS_EXTENDED : 0;
|
||||
input->KeyboardEvent(input, kbdFlags, scanCode);
|
||||
freerdp_input_send_keyboard_event_2(input, !(flags & LLKHF_UP), rdp_scancode);
|
||||
|
||||
if (p->vkCode == VK_CAPITAL)
|
||||
DEBUG_KBD("caps lock is processed on client side too to toggle caps lock indicator");
|
||||
|
@ -58,41 +58,33 @@ boolean xf_kbd_key_pressed(xfInfo* xfi, KeySym keysym)
|
||||
|
||||
void xf_kbd_send_key(xfInfo* xfi, boolean down, uint8 keycode)
|
||||
{
|
||||
uint16 flags;
|
||||
RDP_SCANCODE rdp_scancode;
|
||||
uint8 scancode;
|
||||
boolean extended;
|
||||
rdpInput* input;
|
||||
|
||||
input = xfi->instance->input;
|
||||
rdp_scancode = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(keycode);
|
||||
scancode = rdp_scancode_code(rdp_scancode);
|
||||
extended = rdp_scancode_extended(rdp_scancode);
|
||||
|
||||
if (scancode == 0)
|
||||
if (rdp_scancode == RDP_SCANCODE_UNKNOWN)
|
||||
{
|
||||
/* unknown key */
|
||||
printf("Unknown key with X keycode 0x%02x\n", keycode);
|
||||
}
|
||||
else if ((scancode == 0x46) && extended &&
|
||||
else if (rdp_scancode == RDP_SCANCODE_PAUSE &&
|
||||
!xf_kbd_key_pressed(xfi, XK_Control_L) && !xf_kbd_key_pressed(xfi, XK_Control_R))
|
||||
{
|
||||
/* Pause without Ctrl has to be sent as Ctrl + NumLock. */
|
||||
if (down)
|
||||
{
|
||||
input->KeyboardEvent(input, KBD_FLAGS_DOWN, 0x1D); /* Ctrl down */
|
||||
input->KeyboardEvent(input, KBD_FLAGS_DOWN, 0x45); /* NumLock down */
|
||||
input->KeyboardEvent(input, KBD_FLAGS_RELEASE, 0x1D); /* Ctrl up */
|
||||
input->KeyboardEvent(input, KBD_FLAGS_RELEASE, 0x45); /* NumLock up */
|
||||
freerdp_input_send_keyboard_event_2(input, true, RDP_SCANCODE_LCONTROL);
|
||||
freerdp_input_send_keyboard_event_2(input, true, RDP_SCANCODE_NUMLOCK);
|
||||
freerdp_input_send_keyboard_event_2(input, false, RDP_SCANCODE_LCONTROL);
|
||||
freerdp_input_send_keyboard_event_2(input, false, RDP_SCANCODE_NUMLOCK);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flags = (extended) ? KBD_FLAGS_EXTENDED : 0;
|
||||
flags |= (down) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE;
|
||||
freerdp_input_send_keyboard_event_2(input, down, rdp_scancode);
|
||||
|
||||
input->KeyboardEvent(input, flags, scancode);
|
||||
|
||||
if ((scancode == 0x3A) && (down == false)) /* caps lock was released */
|
||||
if ((rdp_scancode == RDP_SCANCODE_CAPITAL) && (down == false))
|
||||
{
|
||||
uint32 syncFlags;
|
||||
syncFlags = xf_kbd_get_toggle_keys_state(xfi);
|
||||
|
@ -24,6 +24,7 @@ typedef struct rdp_input rdpInput;
|
||||
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/keyboard_scancode.h>
|
||||
|
||||
/* keyboard Flags */
|
||||
#define KBD_FLAGS_EXTENDED 0x0100
|
||||
@ -79,4 +80,10 @@ FREERDP_API void freerdp_input_send_unicode_keyboard_event(rdpInput* input, uint
|
||||
FREERDP_API void freerdp_input_send_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
|
||||
FREERDP_API void freerdp_input_send_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y);
|
||||
|
||||
#define freerdp_input_send_keyboard_event_2(input, down, rdp_scancode) \
|
||||
freerdp_input_send_keyboard_event(input, \
|
||||
(rdp_scancode_extended(rdp_scancode) ? KBD_FLAGS_EXTENDED : 0) | \
|
||||
((down) ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE), \
|
||||
rdp_scancode_code(rdp_scancode))
|
||||
|
||||
#endif /* __INPUT_API_H */
|
||||
|
@ -157,7 +157,7 @@ typedef uint32 RDP_SCANCODE; /* Our own representation of a RDP protocol scancod
|
||||
#define RDP_SCANCODE_F22 mk_rdp_scancode(0x6D, false) /* VK_F22 */
|
||||
#define RDP_SCANCODE_F23 mk_rdp_scancode(0x6E, false) /* VK_F23 */
|
||||
#define RDP_SCANCODE_F24 mk_rdp_scancode(0x6F, false) /* VK_F24 */
|
||||
#define RDP_SCANCODE_NUMLOCK mk_rdp_scancode(0x45, false) /* VK_NUMLOCK */
|
||||
#define RDP_SCANCODE_NUMLOCK mk_rdp_scancode(0x45, false) /* VK_NUMLOCK */ /* Note: when this seems to appear in PKBDLLHOOKSTRUCT it means Pause which must be sent as Ctrl + NumLock */
|
||||
#define RDP_SCANCODE_SCROLL mk_rdp_scancode(0x46, false) /* VK_SCROLL */
|
||||
#define RDP_SCANCODE_LSHIFT mk_rdp_scancode(0x2A, false) /* VK_LSHIFT */
|
||||
#define RDP_SCANCODE_RSHIFT mk_rdp_scancode(0x36, false) /* VK_RSHIFT */
|
||||
@ -210,4 +210,8 @@ typedef uint32 RDP_SCANCODE; /* Our own representation of a RDP protocol scancod
|
||||
/* #define RDP_SCANCODE_PA1 VK_PA1 */
|
||||
/* #define RDP_SCANCODE_OEM_CLEAR VK_OEM_CLEAR */
|
||||
|
||||
/* _not_ valid scancode, but this is what a windows PKBDLLHOOKSTRUCT for NumLock contains */
|
||||
#define RDP_SCANCODE_NUMLOCK_EXTENDED mk_rdp_scancode(0x45, true) /* should be RDP_SCANCODE_NUMLOCK */
|
||||
#define RDP_SCANCODE_RSHIFT_EXTENDED mk_rdp_scancode(0x36, true) /* should be RDP_SCANCODE_RSHIFT */
|
||||
|
||||
#endif /* __FREERDP_LOCALE_KEYBOARD_RDP_SCANCODE_H */
|
||||
|
Loading…
Reference in New Issue
Block a user