For remote control related software (telecommuting, distance education, Remote Assistance, etc.), mouse, key simulation is essential. In the Windows environment, the Windows API provides two ways to complete the mouse and key simulation easily: Mouse_event, keybd_event. When simulating the mouse button click, first calculate the mouse position x, y (using ClientToScreen), and move the controlled end mouse position to the x, y position, that is, the mouse move event (Setcursorpos), and then use mouse_event to simulate the need to perform the mouse behavior, Mainly for pressing, bouncing up. The key of the simulation is mainly the button press and bounce up.
Mouse Simulation:
1 //Mouseeventf_leftdown = $0002;//left button pressed2 //mouseeventf_leftup = $0004;//left button bouncing3 //Mouseeventf_rightdown = $0008;//Right-click4 //mouseeventf_rightup = $0010;//Right-click Bounce5 //Mouseeventf_middledown = $0020;//middle Key Press6 //mouseeventf_middleup = $0040;//middle key bouncing up7 8 //set the mouse position (analog mouse must first set the correct position)9 Setcursorpos (X, Y)Ten One //left-click (right and Middle keys are similar) AMouse_event (Mouseeventf_leftdown, x, Y,0,0) -Mouse_event (Mouseeventf_leftup, x, Y,0,0) - //left-click Combo notation theMouse_event (Mouseeventf_leftdownorMouseeventf_leftup, X, Y,0,0) - - //left Double-click (right, middle key similar to this) -Mouse_event (Mouseeventf_leftdown, x, Y,0,0) +Mouse_event (Mouseeventf_leftup, x, Y,0,0) -Mouse_event (Mouseeventf_leftdown, x, Y,0,0) +Mouse_event (Mouseeventf_leftup, x, Y,0,0) A //left-click Combo notation atMouse_event (Mouseeventf_leftdownorMouseeventf_leftup, X, Y,0,0) -Mouse_event (Mouseeventf_leftdownorMouseeventf_leftup, X, Y,0,0)
MouseEvent
Keyboard emulation:
1 //Press the A key ord (' a ') to take the ASCII value of the key2Keybd_event (Ord ('A'),0,0,0);3 //release the A key (a keystroke on the keyboard performs a press and release of the corresponding key)4Keybd_event (Ord ('A'),0, Keyeventf_keyup,0);5 6 //Key combinations: Ctrl + A7Keybd_event (Vk_control,0,0,0);8Keybd_event (Ord ('A'),0,0,0);9Keybd_event (Ord ('A'),0, Keyeventf_keyup,0);TenKeybd_event (Vk_control,0, Keyeventf_keyup,0);
Remote control of mouse, button simulation