Need a project done?

C++ Programming Developer

Search This Blog

Mouse Handling in C++

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;
"Don't let anyone ever make you feel like you don't deserve what you want."