C + + mouse emulation program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.