Hi all, i'm looking into doing a little bit of work with the mouse in console applications on windows. I'm using windows.h to get access to functions such as ReadConsoleInput. I've created a simple program that just prints a string whenever the left most mouse button is clicked. However sometimes it works fine sometimes it doesn't. By doesn't work it seems to be that when i run it if my curser is out side the console window then when i move my mouse into the console window it crashes. If it is inside to begin with then i seems to be ok....quite odd.
I was wondering if you could shed some light on where i have gone wrong thanks.
#include <iostream>
#include <windows.h>
using namespace std;
int main(void){
HANDLE stin = GetStdHandle(STD_INPUT_HANDLE);
DWORD NumRead;
DWORD numEvents;
while(1){
GetNumberOfConsoleInputEvents(stin, &numEvents);
INPUT_RECORD *inputStat = new INPUT_RECORD[numEvents];
ReadConsoleInput(stin, inputStat, 1, &NumRead);
if(NumRead != 0){
for(int i = 0; i < NumRead; i++){
if(inputStat[i].EventType==MOUSE_EVENT){
if (inputStat[i].Event.MouseEvent.dwButtonState & 0x0001){
std::cout << "Clicked\n";
}
}
}
delete inputStat;
}
}
return 0;
}
Chris