This article mainly introduces the simulation of mouse events and the implementation of the Code, a friend in need can refer to the
Simulating mouse events can generally be done by mouse_event () and SendInput () methods. Mouse_event () is gradually replaced by SendInput () in later versions of Windows. SendInput () analog mouse movement in the event, the flag bit value is different, the meaning of the input coordinates are also different. Simply put, adding a Mouseeventf_absolute flag indicates that the mouse movement is positioned through absolute coordinates, at which point the coordinates are converted. The cursor is divided into 65,535 small pieces on the screen and can be converted by: Code as follows: Double FX = x * (65535.0f/fscreenwidth); Double fy = y * (65535.0f/fscreenheight); If the Mouseeventf_absolute flag bit is not used, the coordinate is the displacement relative to the previous coordinate. SendInput () mouse time usage structure is as follows: The code is as follows: typedef struct TAGMOUSEINPUT { LONG dx; &NBSP ; LONG dy; DWORD Mousedata; DWORD dwflags; DWORD time; ULONG_PTR dwExtraInfo; Mouseinput, *pmouseinput, far* lpmouseinput; The MSDN is fully explained as follows:  DX The absolute position of the mouse, or the value of the dwflags member generated from the last mouse event's exercise. The x coordinates of the mouse are specified as absolute data, relative to the number of moving pixels that are specified as data. dy The absolute position of the mouse, or the value of the dwflags member resulting from the last mouse event's exercise. The y-coordinate of the mouse is specified as absolute data, relative to the number of moving pixels that are specified as data. mousedata If the dwflags contains mouseeventf_wheel,mousedata specifies the amount of wheel movement. PositiveIndicates that the wheel rotates forward, away from the user, and a negative value indicates that the wheel rotates backwards, which is toward the user. The scroll wheel is defined as Wheel_delta, which is 120. The following code demonstrates several specific actions of the mouse. 1, how can I simulate mouse events in my application? has two API functions that can be used: mouse_event () and SendInput ();  2, which API function should I use? in Windows NT/2000/XP, the Mouse_event () function has been replaced by the SendInput () function. Therefore, on these operating systems, you should use the SendInput () function. (unless you need to provide backward compatibility with Windows98 etc.).  3, how to use the SendInput () function to simulate the click of the left mouse button? Code as follows: void Leftclick () { INPUT Input={0}; //left click & nbsp Input.type = input_mouse; Input.mi.dwFlags = Mouseeventf_leftdown; :: SendInput (1,&input,sizeof (Input)); //left button up :: ZeroMemory (&input,sizeof (Input)); Input.type = input_mouse; Input.mi.dwFlags = Mouseeventf_leftup; :: SendInput (1,&input,sizeof) (InpuT)); 4, how to use the SendInput () function to simulate the right mouse click? code as follows: void RightClick () { INPUT Input={0}; //Right button press & nbsp Input.type = input_mouse; Input.mi.dwFlags = Mouseeventf_rightdown; :: SendInput (1,&input,sizeof (Input)); //Right button lift :: ZeroMemory (&input,sizeof (Input)); Input.type = input_mouse; Input.mi.dwFlags = Mouseeventf_rightup; :: SendInput (1,&input,sizeof (Input)); } 5, how to use the SendInput () function to simulate the movement of the mouse? Code as follows: void MouseMove (int x, int y) { double fscreenwidth =:: Getsystemme Trics (Sm_cxscreen) -1; Double fscreenheight =:: GetSystemMetrics (sm_cyscreen) -1;   ; Double FX = x* (65535.0f/fscreenwidth); Double fy = y* (65535.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)); 6, how to use the SendInput () function to simulate the click of the mouse button? Code as follows: void Middleclick () { INPUT Input={0}; //Set Wheel volume Input.type = input_mouse; Input.mi.dwFlags = Mouseeventf_wheel; Input.mi.mouseData = 500; :: SendInput (1,&input,sizeof (Input)); }