mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-24 04:04:31 +00:00
Added unicode key input support.
This commit is contained in:
@@ -340,13 +340,7 @@ void KVM_InitMouseCursors(void *pendingPackets)
|
||||
void MouseAction(double absX, double absY, int button, short wheel)
|
||||
{
|
||||
INPUT mouse;
|
||||
|
||||
if (button == 0x88)
|
||||
{
|
||||
// Double click indication, no nothing on windows.
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == 0x88) return; // Double click indication, no nothing on windows.
|
||||
mouse.type = INPUT_MOUSE;
|
||||
mouse.mi.dx = (long)absX;
|
||||
mouse.mi.dy = (long)absY;
|
||||
@@ -359,58 +353,10 @@ void MouseAction(double absX, double absY, int button, short wheel)
|
||||
SendInput(1, &mouse, sizeof(INPUT));
|
||||
}
|
||||
|
||||
|
||||
// Handling keyboard Input
|
||||
// MSDN References:
|
||||
// Keyboard input structure: http://msdn.microsoft.com/en-us/library/ms646271%28v=VS.85%29.aspx
|
||||
// Virtual key-codes: http://msdn.microsoft.com/en-us/library/dd375731%28v=VS.85%29.aspx
|
||||
BYTE kstate[255] = { 0 };
|
||||
void KeyActionEx(unsigned char keycode, int up, HKL layout)
|
||||
{
|
||||
WCHAR buf[16];
|
||||
HWND windowHandle = GetForegroundWindow();
|
||||
INPUT key;
|
||||
if (windowHandle == NULL) return;
|
||||
SetForegroundWindow(windowHandle);
|
||||
|
||||
if (keycode == VK_CAPITAL)
|
||||
{
|
||||
if (up == 0)
|
||||
{
|
||||
kstate[VK_CAPITAL] = (kstate[VK_CAPITAL] == 0xFF ? 0x00 : 0xFF);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (up == 1)
|
||||
{
|
||||
kstate[keycode] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
kstate[keycode] = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
ToUnicodeEx(keycode, MapVirtualKeyEx(keycode, MAPVK_VK_TO_VSC, layout), kstate, buf, 16, 0, layout);
|
||||
uint32_t vc = ((uint32_t*)buf)[0];
|
||||
|
||||
key.type = INPUT_KEYBOARD;
|
||||
key.ki.wVk = 0;
|
||||
key.ki.dwFlags = KEYEVENTF_UNICODE;
|
||||
if (up == 1) key.ki.dwFlags |= KEYEVENTF_KEYUP; // 1 = UP
|
||||
//else if (up == 3) key.ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP; // 3 = EXUP
|
||||
//else if (up == 4) key.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; // 4 = EXDOWN
|
||||
key.ki.time = 0;
|
||||
key.ki.wScan = (WORD)vc;
|
||||
key.ki.dwExtraInfo = 0;
|
||||
SendInput(1, &key, sizeof(INPUT));
|
||||
}
|
||||
|
||||
void KeyAction(unsigned char keycode, int up)
|
||||
{
|
||||
HWND windowHandle = GetForegroundWindow();
|
||||
INPUT key;
|
||||
HWND windowHandle = GetForegroundWindow();
|
||||
if (windowHandle == NULL) return;
|
||||
SetForegroundWindow(windowHandle);
|
||||
key.type = INPUT_KEYBOARD;
|
||||
@@ -421,8 +367,28 @@ void KeyAction(unsigned char keycode, int up)
|
||||
else if (up == 4) key.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; // 4 = EXDOWN
|
||||
key.ki.time = 0;
|
||||
key.ki.wScan = (WORD)MapVirtualKey((UINT)keycode, MAPVK_VK_TO_VSC); // This is required to make RDP client work.
|
||||
key.ki.dwExtraInfo = 0;
|
||||
key.ki.dwExtraInfo = GetMessageExtraInfo();
|
||||
SendInput(1, &key, sizeof(INPUT));
|
||||
//printf("KEY keycode: %d, up: %d, scan: %d\r\n", keycode, up, key.ki.wScan);
|
||||
}
|
||||
|
||||
void KeyActionUnicode(WORD unicode, int up)
|
||||
{
|
||||
INPUT key;
|
||||
HWND windowHandle = GetForegroundWindow();
|
||||
if (windowHandle == NULL) return;
|
||||
SetForegroundWindow(windowHandle);
|
||||
key.type = INPUT_KEYBOARD;
|
||||
key.ki.wVk = 0;
|
||||
key.ki.dwFlags = KEYEVENTF_UNICODE;
|
||||
if (up == 1) key.ki.dwFlags = KEYEVENTF_KEYUP; // 1 = UP
|
||||
else if (up == 3) key.ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP; // 3 = EXUP
|
||||
else if (up == 4) key.ki.dwFlags = KEYEVENTF_EXTENDEDKEY; // 4 = EXDOWN
|
||||
key.ki.time = 0;
|
||||
key.ki.wScan = unicode;
|
||||
key.ki.dwExtraInfo = GetMessageExtraInfo();
|
||||
SendInput(1, &key, sizeof(INPUT));
|
||||
//printf("KEY unicode: %d, up: %d\r\n", unicode, up);
|
||||
}
|
||||
|
||||
// Windows 8 Touch Related Support
|
||||
|
||||
Reference in New Issue
Block a user