使用函数system()时,无法捕获任何鼠标事件。 我已经知道system()函数是一个shell命令,但是为什么使用此命令会阻止捕获鼠标事件?
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE ConsoleWin;
INPUT_RECORD eventMsg;
DWORD Pointer;
//system("mode con cols=140 lines=40"); //after using this function,I cannot catch any mouse event
while (1)
{
ConsoleWin = GetStdHandle(STD_INPUT_HANDLE);//Get the console window
ReadConsoleInput(ConsoleWin,&eventMsg,1,&Pointer);//Read input msg
if (eventMsg.EventType == MOUSE_EVENT && eventMsg.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_pressed) {
printf("Left button clicked.");
}
else if (eventMsg.EventType == MOUSE_EVENT && eventMsg.Event.MouseEvent.dwButtonState == RIGHTMOST_BUTTON_pressed) {
printf("Right button clicked.");
}
}
return 0;
}