Maus in der konsole?



  • wie kann ich die maus in der konsole verwenden?
    ich möchte auf mausklicks überprüfen!
    und die position bestimmen!



  • stötti wir sind heute um 18:19 bei dir in wels

    für maus siehe Konsolen-FAQ, hier der code aus der FAQ:

    #include <windows.h> 
    #include <winuser.h> 
    #include <stdio.h> 
    #include <string.h> 
    #include <conio.h> 
    
    int main(void) 
    { 
        BOOL bSuccess; 
        HANDLE hStdIn, hStdOut; /* standard input, output handles */ 
        DWORD dwMode; 
        /* array of console input event records */ 
        INPUT_RECORD inputBuffer; 
        DWORD dwInputEvents; /* number of events actually read */ 
        CHAR bOutBuf[256]; /* buffer to format event information into */ 
        CONSOLE_CURSOR_INFO cci; /* used when turning off the cursor */ 
        CONSOLE_SCREEN_BUFFER_INFO csbi; /* used to get cursor position */ 
        OSVERSIONINFO osVer; /* for GetVersionEx() */ 
        /* check if Win32s, if so, display notice and terminate */ 
        osVer.dwOSVersionInfoSize = sizeof(osVer); 
        bSuccess = GetVersionEx(&osVer); 
        if (osVer.dwPlatformId == VER_PLATFORM_WIN32s) 
        { 
            MessageBox(NULL, 
            "This application cannot run on Windows 3.1.", 
            "Error: Windows NT or Windows 95 Required to Run", MB_OK ); 
            return(1); 
        } 
    
        bSuccess = GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); 
    
        if ((csbi.dwCursorPosition.X) | (csbi.dwCursorPosition.Y)) /* either non-zero? */ 
        { 
            bSuccess = FreeConsole();         
            bSuccess = AllocConsole(); 
        } 
        /* let's put up a meaningful console title */ 
        bSuccess = SetConsoleTitle("elises window32 api demo"); 
        /* get the standard handles */ 
        hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); 
        hStdIn = GetStdHandle(STD_INPUT_HANDLE); 
        /* set up mouse and window input */ 
        bSuccess = GetConsoleMode(hStdIn, &dwMode); 
        /* ENABLE_ECHO_INPUT. */ 
        bSuccess = SetConsoleMode(hStdIn, (dwMode & ~(ENABLE_LINE_INPUT |ENABLE_ECHO_INPUT)) | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT); 
        /* save then hide the cursor */ 
        cci.dwSize = 100; 
        cci.bVisible = FALSE; 
        bSuccess = SetConsoleCursorInfo(hStdOut, &cci); 
        do{ 
            /* read an input events from the input event queue */ 
           bSuccess = ReadConsoleInput(hStdIn, &inputBuffer, 1, &dwInputEvents); 
           switch (inputBuffer.EventType){   
            case KEY_EVENT: 
                if (inputBuffer.Event.KeyEvent.bKeyDown){ 
                    /* display the key event info on the status line */ 
                    sprintf(bOutBuf, "key: virtual=%d ascii=%c", 
                    inputBuffer.Event.KeyEvent.wVirtualKeyCode, 
                    inputBuffer.Event.KeyEvent.uChar.AsciiChar); 
                    printf("%s", bOutBuf); 
                } 
                break; 
    
            case MOUSE_EVENT:   
                sprintf(bOutBuf, "mouse: %s at %d, %d",(inputBuffer.Event.MouseEvent.dwEventFlags == MOUSE_MOVED ?"moved" : "clicked"), inputBuffer.Event.MouseEvent.dwMousePosition.X,inputBuffer.Event.MouseEvent.dwMousePosition.Y); 
                printf("%s", bOutBuf);               
                  break;     
           } 
    
        }while ( inputBuffer.Event.KeyEvent.uChar.AsciiChar!='E'&&inputBuffer.Event.KeyEvent.uChar.AsciiChar!='e'); 
        return 0;
    

    MfG SideWinder



  • ok bast!
    thx für code


Anmelden zum Antworten