in src/keyboard_win.cc [29:64]
std::string GetStrFromKeyPress(UINT key_code, int modifiers, BYTE *keyboard_state, UINT clear_key_code, UINT clear_scan_code) {
memset(keyboard_state, 0, 256);
if (modifiers & kShiftKeyModifierMask) {
keyboard_state[VK_SHIFT] |= 0x80;
}
if (modifiers & kControlKeyModifierMask) {
keyboard_state[VK_CONTROL] |= 0x80;
}
if (modifiers & kAltKeyModifierMask) {
keyboard_state[VK_MENU] |= 0x80;
}
UINT scan_code = ::MapVirtualKeyW(key_code, MAPVK_VK_TO_VSC);
wchar_t chars[5];
int code = ::ToUnicode(key_code, scan_code, keyboard_state, chars, 4, 0);
if (code == -1) {
// dead key
if (chars[0] == 0 || iswcntrl(chars[0])) {
return std::string();
}
code = 1;
}
ClearKeyboardBuffer(clear_key_code, clear_scan_code, keyboard_state);
if (code <= 0 || (code == 1 && iswcntrl(chars[0]))) {
return std::string();
}
return vscode_keyboard::UTF16toUTF8(chars, code);
}