P
P
Pavel2014-05-18 11:00:35
Programming
Pavel, 2014-05-18 11:00:35

How to pass keypress event to sega mega drive Gens (Windows) emulator window?

Good afternoon.
There is a server (written in qt), which receives commands from clients (also qt). The server executes these commands by emulating keystrokes in the system. for example, the command "player1#dr a" comes from the client, then the server "presses" the keyboard keys that are responsible for the "down", "right", "A" buttons on the joystick of the sega emulator.
Outside the emulator window everything works fine. The server accepts commands from the client and "presses" the keys. For example, this can be seen if you open the Notepad program. The server still accepts commands and "presses" the keys, since the notepad shows how commands are typed from the client.
But if you move the focus to the emulator window, then nothing happens. It seems that the emulator window does not receive the system keypress message. Has anyone encountered this behavior of windows in Windows? What could be the reason? I really want to play Mortal Kombat by typing a series of commands and check "whose kung fu is cooler".
Emulator: Gens v2.14 Keystroke
emulation code in Windows:

void MyServer::sendKeyEventToSystem(Qt::Key qtKey)
{
    #ifdef Q_OS_WIN32
        INPUT ip; //устройство ввода
        ip.type = INPUT_KEYBOARD;
        ip.ki.wScan = 0;
        ip.ki.time = 0;
        ip.ki.dwExtraInfo = 0;

        //в зависимости от типа клавиши
        switch (qtKey)
        {
            // Player 1
            case Qt::Key_A: // left
                ip.ki.wVk = 0x41;
                break;
            ...
        }

        //посылаем событие нажатия клавиши
        ip.ki.dwFlags = 0;
        SendInput(1, &ip, sizeof(INPUT));

        //а затем отжатия клавиши
        ip.ki.dwFlags = KEYEVENTF_KEYUP;
        SendInput(1, &ip, sizeof(INPUT));
    #endif
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question