Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mouse Click message [closed]

Tags:

c++

visual-c++

How we can make mouse click event in a certain position without moving mouse(I mean that make computer think a position is clicked with mouse) with C++

like image 812
zoli Avatar asked Sep 11 '12 05:09

zoli


1 Answers

The SendInput function in windows API will get you started. Have a look at the following link for the definition of the method,its input parameters and return values :
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx

You can follow the links in the page to know more about the structures and data-types used in the function.

Update : You can start with something like this

#include<Windows.h>
int main()
{
    INPUT input;
    input.type=INPUT_MOUSE;
    input.mi.dx=0;
    input.mi.dy=0;
    input.mi.dwFlags=(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE|MOUSEEVENTF_RIGHTDOWN|MOUSEEVENTF_RIGHTUP);
    input.mi.mouseData=0;
    input.mi.dwExtraInfo=NULL;
    input.mi.time=0;
    SendInput(1,&input,sizeof(INPUT));
    return 0;
}

This will automatically move your mouse to the top left corner of the screen and make a right-click. Now, if you mean to make a click somewhere on the screen without moving your mouse, I think that is not possible using SendInput(). You do not need to worry about moving the mouse as your program will do it by itself. That is what the 'MOUSEEVENTF_MOVE' flag tells the program to do. If you do not use the flag, then the click will take place at the current position of your mouse.

like image 119
sandyiscool Avatar answered Sep 20 '22 18:09

sandyiscool