Use the code to simulate keyboard and mouse operations. The keybd_event/mouse_event or sendinput API functions are mainly used. The usage example is as follows (with comments ):
/*
* Simulate keyboard input. Press the window key (win key) as an example.
*/
// Keybd_event analog keyboard input example
: Keybd_event (vk_lwin, 0, 0, 0); // press the win key
: Keybd_event (vk_lwin, 0, keyeventf_keyup, 0); // The win key is displayed.
// Sendinput analog keyboard input example
Input keyinput [2];
Memset (keyinput, 0, sizeof (keyinput ));
Keyinput [0]. type = keyinput [1]. type = input_keyboard; // set it to keyboard input
Keyinput [0]. Ki. wvk = keyinput [1]. Ki. wvk = vk_lwin; // operate the win key
Keyinput [1]. Ki. dwflags = keyeventf_keyup; //
: Sendinput (_ countof (keyinput), keyinput, sizeof (input ));
/*
* Simulate the mouse input. Take the Start menu as an example.
* Because my machine resolution is 1440*900, the mouse position (0,880) is just at the Start Menu position.
*/
// Example of mouse input simulation using mouse_event
: Setcursorpos (0,880); // set the current mouse position to the Start Menu position
: Mouse_event (mouseeventf_absolute | mouseeventf_leftdown, 0, 0, 0, null); // press the simulated left button.
: Mouse_event (mouseeventf_absolute | mouseeventf_leftup, 0, 0, 0, null); // simulate left-click pop-up
// Example of sendinput simulating mouse input
: Setcursorpos (0,880); // set the current mouse position to the Start Menu position
Input mouseinput [2];
Memset (mouseinput, 0, sizeof (mouseinput ));
Mouseinput [0]. type = mouseinput [1]. type = input_mouse; // set it to mouse input
Mouseinput [0]. Mi. dwflags = mouseeventf_absolute | mouseeventf_leftdown; // press the left button
Mouseinput [1]. Mi. dwflags = mouseeventf_absolute | mouseeventf_leftup; // The left button pops up.
: Sendinput (_ countof (mouseinput), mouseinput, sizeof (input ));