Simulate mouse and keyboard

Source: Internet
Author: User

Keybd_event function analog keyboard input see: http://baike.baidu.com/view/1080077.html

// Sample code

Keybd_event (vk_numlock, 0, keyeventf_extendedkey | 0, 0); // press num
Keybd_event (vk_numlock, 0, keyeventf_extendedkey | keyeventf_keyup, 0); // cancel pressing num

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
For more information, see http://baike.baidu.com/view/1471905.html.

// Sample code

Input IP [2];
Memset (IP, 0, sizeof (input ));
IP [0]. type = IP [1]. type = input_keyboard;
IP [0]. Ki. wvk = IP [1]. Ki. wvk = vk_numlock;
IP [1]. Ki. dwflags = keyeventf_keyup;
Sendinput (2, IP, sizeof (input ));


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 (2, keyinput, sizeof (input ));

Mouse_event
For more information about simulated mouse input, see http://baike.baidu.com/view/1080208.htm.

// Sample code
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

Sendinput simulates mouse input
// Example

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 (2, mouseinput, sizeof (input ));

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.