I was able to use a mouse in my console. When i compile and the first thing i call is the mouse code, it works perfectly; however, when i need to call that function later on the game, it freezes and simply doesn't work. I've been told i could clean the input buffer but i'm not sure that's the problem. Does anyone have an idea?
// LightUp.cpp : implementation of the CLightUp class
HANDLE hIn;
bool Continue = TRUE;
INPUT_RECORD InRec;
DWORD NumRead;
HWND window = GetConsoleWindow();
POINT cursorPos;
RECT wpos;
int x = 0;
int y = 0;
hIn = GetStdHandle(STD_INPUT_HANDLE);
cout << hIn << endl;
if (cin.fail()) { cin.clear(); cin.ignore(1000, '\n'); }
while (Continue) {
ReadConsoleInput(hIn, &InRec, 1, &NumRead);
switch (InRec.EventType)
{
case MOUSE_EVENT: if (GetAsyncKeyState(VK_LBUTTON))
{
GetWindowRect(window, &wpos);
GetCursorPos(&cursorPos);
cursorPos.x -= wpos.left;
cursorPos.y -= wpos.top;
x = (cursorPos.x - 5) / 16;
y = (cursorPos.y - 25) / 24;
cout << x << " " << y << endl;
//row = x; col = y;
}
else if (GetAsyncKeyState(VK_RBUTTON)){
GetWindowRect(window, &wpos);
GetCursorPos(&cursorPos);
cursorPos.x -= wpos.left;
cursorPos.y -= wpos.top;
x = (cursorPos.x - 5) / 8;
y = (cursorPos.y - 25) / 12;
cout << x << " " << y << endl;
// row = x; col = y;
cout << hIn << endl;
}
break;
}
}