[fix] fix mac-to-windows symbol key input

This commit is contained in:
dijunkun
2026-03-23 22:30:58 +08:00
parent 21b179e01c
commit f4e28d8774
2 changed files with 119 additions and 7 deletions
@@ -54,11 +54,28 @@ int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
input.type = INPUT_KEYBOARD;
input.ki.wVk = (WORD)key_code;
if (!is_down) {
input.ki.dwFlags = KEYEVENTF_KEYUP;
const UINT scan_code =
MapVirtualKeyW(static_cast<UINT>(key_code), MAPVK_VK_TO_VSC_EX);
if (scan_code != 0) {
input.ki.wVk = 0;
input.ki.wScan = static_cast<WORD>(scan_code & 0xFF);
input.ki.dwFlags |= KEYEVENTF_SCANCODE;
if ((scan_code & 0xFF00) != 0) {
input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
}
}
if (!is_down) {
input.ki.dwFlags |= KEYEVENTF_KEYUP;
}
UINT sent = SendInput(1, &input, sizeof(INPUT));
if (sent != 1) {
LOG_WARN("SendInput failed for key_code={}, is_down={}, err={}", key_code,
is_down, GetLastError());
return -1;
}
SendInput(1, &input, sizeof(INPUT));
return 0;
}
} // namespace crossdesk
} // namespace crossdesk