'How do anti-cheats protect against input emulation?

There is one game on the Unreal Engine 2 (pirate MMORPG with anti-cheat). I'm using reshade library to hook some functions including dinput/window input handling.

With the SendInput function i can send input but only in the active input field. F1-F12 or 1-9 keys are bind to the panel of skills. I tried to send these keys but nothing happens.

int SendKey(const wchar_t *text)
{
    INPUT *keystroke;
    UINT i, character_count, keystrokes_to_send, keystrokes_sent;
    assert(text != NULL);

    //Fill in the array of keystrokes to send.

    character_count = wcslen(text);
    keystrokes_to_send = character_count * 2;
    keystroke = new INPUT[keystrokes_to_send];
    for (i = 0; i < character_count; ++i)
    {
        keystroke[i * 2].type = INPUT_KEYBOARD;
        keystroke[i * 2].ki.wVk = 0;
        keystroke[i * 2].ki.wScan = text[i];
        keystroke[i * 2].ki.dwFlags = KEYEVENTF_UNICODE;
        keystroke[i * 2].ki.time = 0;
        keystroke[i * 2].ki.dwExtraInfo = GetMessageExtraInfo();

        keystroke[i * 2 + 1].type = INPUT_KEYBOARD;
        keystroke[i * 2 + 1].ki.wVk = 0;
        keystroke[i * 2 + 1].ki.wScan = text[i];
        keystroke[i * 2 + 1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
        keystroke[i * 2 + 1].ki.time = 0;
        keystroke[i * 2 + 1].ki.dwExtraInfo = GetMessageExtraInfo();
    }

    //Send the keystrokes.
    keystrokes_sent = SendInput((UINT)keystrokes_to_send, keystroke, sizeof(*keystroke));
    delete[] keystroke;
    return 0;
}

Or I can somehow use dinput to send keys?

I know that anti-cheat uses kbdHook (From Kernel-Mode) but how can he keep track of where the keys were sent in the game? (if the active input field works for me)?

PS: If I'm missing something please correct me, thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source