2 Stimmen

Senden von Return/Enter-Zeichen an die Konsole mit WriteConsoleInput/WriteConsole

Ich habe das folgende Stück Code. Ich möchte den Befehl "uci" und dann Return/Enter an die Konsole senden. Ich habe jedoch keinen Erfolg damit. Bitte um Ratschläge. Ich danke Ihnen!

#include <conio.h>
#include <iostream>
#include <windows.h>

DWORD WINAPI test(LPVOID lp)
{
    system("edit");

    return 0;
}

int main(int argc, char* argv[])
{
    /*
    HANDLE hConIn = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ, NULL, OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL, 0);
    HANDLE hConOut = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ, NULL, OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL, 0);
    */
    HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE);
    HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD dwTmp;
    INPUT_RECORD ir[4];

    CreateThread(NULL, 0, test,(LPDWORD)0, 0, &dwTmp);

    Sleep( 1000 );

    ir[0].EventType = KEY_EVENT;
    ir[0].Event.KeyEvent.bKeyDown = TRUE;
    ir[0].Event.KeyEvent.dwControlKeyState = 0;
    ir[0].Event.KeyEvent.uChar.UnicodeChar = 'u';
    ir[0].Event.KeyEvent.wRepeatCount = 1;
    ir[0].Event.KeyEvent.wVirtualKeyCode = 'U';
    ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('U', MAPVK_VK_TO_VSC);

    ir[1].EventType = KEY_EVENT;
    ir[1].Event.KeyEvent.bKeyDown = TRUE;
    ir[1].Event.KeyEvent.dwControlKeyState = 0;
    ir[1].Event.KeyEvent.uChar.UnicodeChar = 'c';
    ir[1].Event.KeyEvent.wRepeatCount = 1;
    ir[1].Event.KeyEvent.wVirtualKeyCode = 'C';
    ir[1].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('C', MAPVK_VK_TO_VSC);

    ir[2].EventType = KEY_EVENT;
    ir[2].Event.KeyEvent.bKeyDown = TRUE;
    ir[2].Event.KeyEvent.dwControlKeyState = 0;
    ir[2].Event.KeyEvent.uChar.UnicodeChar = 'i';
    ir[2].Event.KeyEvent.wRepeatCount = 1;
    ir[2].Event.KeyEvent.wVirtualKeyCode = 'I';
    ir[2].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('I', MAPVK_VK_TO_VSC);

    ir[3].EventType = KEY_EVENT;
    ir[3].Event.KeyEvent.bKeyDown = TRUE;
    ir[3].Event.KeyEvent.dwControlKeyState = 0;
    ir[3].Event.KeyEvent.uChar.UnicodeChar = '\n';
    ir[3].Event.KeyEvent.wRepeatCount = 1;
    ir[3].Event.KeyEvent.wVirtualKeyCode = '\n';
    ir[3].Event.KeyEvent.wVirtualScanCode = MapVirtualKey('\n', MAPVK_VK_TO_VSC);

    dwTmp = 0;
    WriteConsoleInput(hConIn, ir, 4, &dwTmp);
    //FlushConsoleInputBuffer(hConIn);
    //WriteConsole(hConIn, "uci\n", 5, &dwTmp, NULL);
    //printf(" dwTmp = %d ", dwTmp);

    Sleep(1000);

    return 0;
}

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X