-
Mouse Movement
Hey. I was wondering how to capture mouse movement. And if the mouse is clicked in a certain area...it would return a different value than any other area. Such that...
Code:
COORD dwCursorPosition={79,23};
and then some sort of "IfMouseIsClickedIn(dwCursorPosition);
it probably won't be that simple, but that's the idea.
-
-
Under MFC, one solution is to add a handler for WM_MOUSEMOVE.
Kuphryn
-
I'm not going to ask anyone to explain everything to me, but could you tell me the functions...maybe some links to MSDN...I can understand MSDN fine once i actually find what i want. Or some tutorials?
-
As Kuphryn has mentioned WM_MOUSEMOVE is one message you could take a look at. Other mouse messages of interest in this regard are WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUUTONDOWN, WM_MBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP.
You need to have some familiarity with message processing, though. And don't forget to check out Adrianxw's 'PtinRect' for when you have some mouse coordinates to work with from the above messages.
There is also GetCursorPos, too.
A search of this board and msdn on any of these should get you started. :)
-
Ok, I've been fulling around for awhile...and this is what I got. I want it to loop and once you click on the 'X' it will quit...what is actually going on here? and how can i fix it please.
Code:
#include <windows.h>
#include <iostream>
using namespace std;
main(){
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ENABLE_MOUSE_INPUT);
bool Continue=1;
INPUT_RECORD InputRecord;
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD dwCursorPosition={79,23};
DWORD Events=0;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),dwCursorPosition);
cout<<'x';
dwCursorPosition.X=0;
dwCursorPosition.Y=0;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),dwCursorPosition);
while(Continue==1){
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE) , &InputRecord, 1, &Events);
if(InputRecord.EventType == MOUSE_EVENT)
{
if(InputRecord.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED){
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&csbi);
if(csbi.dwCursorPosition.X==79 && csbi.dwCursorPosition.Y==23){
Continue=0;
}
}
}
}
return 0;
}
It is a tad revised now, but I'm still having problems. It is atleast accepting mouse input now.
-
Have you looked at
SetCapture()
Don't know if it is needed in console mode