Following is the program for mouse handling in C++ when user left clicks.
#include <iostream>
using namespace std;
int main()
{
while(1){// infinite loop
POINT pt; //Declaring an object of class POINT.
if(GetAsyncKeyState(0x01)) //If user clicks left button.
//GetAsyncKeyState is a C++ function that determines whether a key is up or down. '0x01' is code for left mouse button.
{
GetCursorPos(&pt); //Retrieves the position of the mouse cursor, in screen coordinates.
Sleep(200); //Comment this line and you'll come to know the purpose of this line.
cout << "Click captured at (" << pt.x << "," << pt.y << ")!" << endl; //Simply accessing the x and y coordinates of the object pt.
}
}// closing bracket of infinite loop
return 0;
}
#include <iostream>
using namespace std;
int main()
{
while(1){// infinite loop
POINT pt; //Declaring an object of class POINT.
if(GetAsyncKeyState(0x01)) //If user clicks left button.
//GetAsyncKeyState is a C++ function that determines whether a key is up or down. '0x01' is code for left mouse button.
{
GetCursorPos(&pt); //Retrieves the position of the mouse cursor, in screen coordinates.
Sleep(200); //Comment this line and you'll come to know the purpose of this line.
cout << "Click captured at (" << pt.x << "," << pt.y << ")!" << endl; //Simply accessing the x and y coordinates of the object pt.
}
}// closing bracket of infinite loop
return 0;
}
No comments:
Post a Comment