#pragma once

#include <Windows.h>

class FakeKeyboard {
public:
    static void SimulateKeypress(unsigned short vk) {
        unsigned int scan = MapVirtualKey(vk, MAPVK_VK_TO_VSC);

        INPUT input[2];

        input[0] = { 0 };
        input[0].type = INPUT_KEYBOARD;
        input[0].ki.wVk = vk;
        input[0].ki.wScan = scan;
        input[0].ki.dwFlags = KEYEVENTF_SCANCODE;
        input[0].ki.time = 0;
        input[0].ki.dwExtraInfo = GetMessageExtraInfo();

        input[1] = { 0 };
        input[1].type = INPUT_KEYBOARD;
        input[1].ki.wVk = vk;
        input[1].ki.wScan = scan;
        input[1].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
        input[1].ki.time = 0;
        input[1].ki.dwExtraInfo = GetMessageExtraInfo();

        UINT result = SendInput(2, input, sizeof(INPUT));
    }
};
#pragma once

#include <Windows.h>

class FakeKeyboard {
public:
    static void SimulateKeypress(unsigned short vk) {
        INPUT input = { 0 };
        input.type = INPUT_KEYBOARD;
        input.ki.wVk = vk;
        input.ki.wScan = 0;
        input.ki.dwFlags = 0;
        input.ki.time = 0;
        input.ki.dwExtraInfo = GetMessageExtraInfo();

        /* key down: */
        SendInput(1, &input, sizeof(INPUT));

        /* key up: */
        input.ki.dwFlags = KEYEVENTF_KEYUP;
        SendInput(1, &input, sizeof(INPUT));
    }
};
--- 
+++ 
@@ -5,19 +5,26 @@
 class FakeKeyboard {
 public:
     static void SimulateKeypress(unsigned short vk) {
-        INPUT input = { 0 };
-        input.type = INPUT_KEYBOARD;
-        input.ki.wVk = vk;
-        input.ki.wScan = 0;
-        input.ki.dwFlags = 0;
-        input.ki.time = 0;
-        input.ki.dwExtraInfo = GetMessageExtraInfo();
+        unsigned int scan = MapVirtualKey(vk, MAPVK_VK_TO_VSC);
 
-        /* key down: */
-        SendInput(1, &input, sizeof(INPUT));
+        INPUT input[2];
 
-        /* key up: */
-        input.ki.dwFlags = KEYEVENTF_KEYUP;
-        SendInput(1, &input, sizeof(INPUT));
+        input[0] = { 0 };
+        input[0].type = INPUT_KEYBOARD;
+        input[0].ki.wVk = vk;
+        input[0].ki.wScan = scan;
+        input[0].ki.dwFlags = KEYEVENTF_SCANCODE;
+        input[0].ki.time = 0;
+        input[0].ki.dwExtraInfo = GetMessageExtraInfo();
+
+        input[1] = { 0 };
+        input[1].type = INPUT_KEYBOARD;
+        input[1].ki.wVk = vk;
+        input[1].ki.wScan = scan;
+        input[1].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
+        input[1].ki.time = 0;
+        input[1].ki.dwExtraInfo = GetMessageExtraInfo();
+
+        UINT result = SendInput(2, input, sizeof(INPUT));
     }
 };
Send simulated keystrokes as a single atomic event
