Skip to content

Commit

Permalink
Handle VK_PACKET messages in Rgui/GraphApp Unicode windows to support…
Browse files Browse the repository at this point in the history
… input

injection by external applications using SendInput/KEYEVENTF_UNICODE.


git-svn-id: https://svn.r-project.org/R/trunk@82368 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed May 16, 2022
1 parent 74b5817 commit 9b6de51
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/extra/graphapp/events.c
Expand Up @@ -530,7 +530,35 @@ static long handle_message(HWND hwnd, UINT message,
handle_keydown(LOWORD(wParam));
handle_virtual_keydown(obj, LOWORD(wParam));

if(obj->flags & UseUnicode) {
if((obj->flags & UseUnicode) && LOWORD(wParam) == VK_PACKET) {
/* This handling of VK_PACKET is inspired by gdkevents-win32.c.
Handling the WM_CHAR messages, instead, would be more reliable,
but Unicode windows were designed to not handle those, so it
would require bigger changes. VK_PACKET messages are used
e.g. by Dasher via SendInput/KEYEVENTF_UNICODE. */
int result;
BYTE sta[256];
wchar_t wcs[3];
static wchar_t high = L'\0';

GetKeyboardState(sta);
result = ToUnicodeEx(VK_PACKET, HIWORD(lParam), sta,
wcs, /* 3 */ sizeof(wcs)/sizeof(wchar_t),
1, 0);
if (result == 1) {
if (IsSurrogatePairsHi(wcs[0]))
high = wcs[0];
else if (IsSurrogatePairsLo(wcs[0]) && high != L'\0') {
/* Surrogate pairs block */
handle_char(obj, L'?');
handle_char(obj, L'?');
high = L'\0';
} else {
handle_char(obj, wcs[0]);
high = L'\0';
}
}
} else if(obj->flags & UseUnicode) {
BYTE sta[256];
wchar_t wcs[3];
HKL dwhkl;
Expand Down

0 comments on commit 9b6de51

Please sign in to comment.