console mouse

#include <windows.h>
#include <stdio.h>

int main()
{
    HANDLE Hin,Hout;
    Hin = GetStdHandle(STD_INPUT_HANDLE);
    Hout = GetStdHandle(STD_OUTPUT_HANDLE);
    INPUT_RECORD Mouse;
    DWORD res;
    COORD Pos,cd = {70,107};
    while(1)
    {
        ReadConsoleInput(Hin,&Mouse,1,&res);

        if(Mouse.EventType == MOUSE_EVENT)
        {

            if(Mouse.Event.MouseEvent.dwEventFlags = MOUSE_MOVED)
            {
                Pos = Mouse.Event.MouseEvent.dwMousePosition;
                SetConsoleCursorPosition(Hout,Pos);
                SetConsoleTextAttribute(Hout,FOREGROUND_BLUE | FOREGROUND_RED |FOREGROUND_INTENSITY);
                printf(".");
            }
            SetConsoleCursorPosition(Hout,cd);
            SetConsoleTextAttribute(Hout,FOREGROUND_RED |FOREGROUND_INTENSITY);
            printf("(%03d,%03d)",Pos.X,Pos.Y);
        }
    }
    CloseHandle(Hin);
    CloseHandle(Hout);
    return 0;
}


你可能感兴趣的:(console,鼠标,控制台,mouse)