Use Scan codes instead of Virtual Keys to improve keyboard support in games

This commit is contained in:
loki 2020-01-16 23:57:36 +01:00
parent 7ce24287b3
commit 2ad2222c83

View File

@ -76,13 +76,19 @@ void keyboard(input_t &input, uint16_t modcode, bool release) {
i.type = INPUT_KEYBOARD; i.type = INPUT_KEYBOARD;
auto &ki = i.ki; auto &ki = i.ki;
// ki.dwFlags = KEYEVENTF_SCANCODE; // For some reason, MapVirtualKey(VK_LWIN, MAPVK_VK_TO_VSC) doesn't seem to work :/
if(modcode != VK_LWIN && modcode != VK_RWIN) {
ki.wScan = MapVirtualKey(modcode, MAPVK_VK_TO_VSC);
ki.dwFlags = KEYEVENTF_SCANCODE;
}
else {
ki.wVk = modcode;
}
if(release) { if(release) {
ki.dwFlags = KEYEVENTF_KEYUP; ki.dwFlags = KEYEVENTF_KEYUP;
} }
ki.wVk = modcode;
auto send = SendInput(1, &i, sizeof(INPUT)); auto send = SendInput(1, &i, sizeof(INPUT));
if(send != 1) { if(send != 1) {
BOOST_LOG(warning) << "Couldn't send moue movement input"sv; BOOST_LOG(warning) << "Couldn't send moue movement input"sv;