About the application of mouse simulation program is not uncommon, in the game plug-in or some of the operation of the frequent location of the application of the program is often miraculous.
Compared to the old API is Mouse_event, I started with this in the work, but later only to see the new API in the operation more unified, a little change can also simulate keyboard input (the two are often used together), so use the new API to do. Yes, the new API is named SendInput.
The following does not say nonsense, directly on the code, this code is running on the MFC project, if you want to run in the console or other projects to include the necessary header files. In addition, this program can only simulate the general mouse operation, for some anti-plug program to click on the need to drive-level simulation.
Simulate mouse action functions
void MouseMove (int x, int y)//mouse move to specified position {double fscreenwidth =:: GetSystemMetrics (Sm_cxscreen)-1;//Get screen resolution width double Fscreenheight =:: GetSystemMetrics (Sm_cyscreen)-1;//Get screen resolution height double FX = x* (65535.0f/fscreenwidth);d ouble fy = y* (6553 5.0f/fscreenheight); input input = {0};input.type = Input_mouse;input.mi.dwflags = Mouseeventf_move | MOUSEEVENTF_ABSOLUTE;INPUT.MI.DX = Fx;input.mi.dy = FY; SendInput (1, &input, sizeof (Input)); void Mouseleftdown ()//left mouse button pressed {input input = {0};input.type = Input_mouse;input.mi.dwflags = Mouseeventf_leftdown; SendInput (1, &input, sizeof (Input)); void Mouseleftup ()//left mouse button release {input input = {0};input.type = Input_mouse;input.mi.dwflags = Mouseeventf_leftup; SendInput (1, &input, sizeof (Input)); void Mouserightdown ()//right mouse button Press {input input = {0};input.type = Input_mouse;input.mi.dwflags = Mouseeventf_rightdown; SendInput (1, &input, sizeof (Input)); void Mouserightup ()//right mouse button release {input input = {0};input.type = Input_mouse;input.mi.dwflags = MOuseeventf_rightup; SendInput (1, &input, sizeof (Input));
Each action function with the mouse to complete various actions
Analog mouse Drag box selected ShowWindow (sw_showminimized);//form minimized point mypoint; GetCursorPos (&mypoint);//Gets the current position of the mouse MouseMove (800, 1000);//mouse moves to the specified position mouseleftdown ();//left mouse button under MouseMove (10, 10) ;//Drag the mouse to the specified location sleep (10);//You need to wait here, or drag will have no effect mouseleftup ();//Mouse release MouseMove (mypoint.x, MYPOINT.Y);//Put the mouse back in place
Simulate right mouse button press and release ShowWindow (sw_showminimized);//form minimized mouserightdown (); Sleep (10); Mouserightup ();
C + + mouse emulation program