In the C # program, send a keyboard-based message.

Source: Internet
Author: User

Using System. Runtime. InteropServices;

Introduce keyboard event Functions

[DllImport ("user32.dll")]
Public static extern void keybd_event (byte bVk, byte bScan, int dwFlags, int dwExtraInfo );
Parameters:

BVk: defines a virtual key code. The key value must be 1 ~ In the range of 254.

BScan: The hardware scan code that defines the key.

DwFlags: A flag set that defines the name of a function operation. The application can use a combination of the following predefined constants to set the flag.

KEYEVENTF_EXETENDEDKEY: if this value is specified, the first value of the scan code is the prefix byte of OXEO (224. KEYEVENTF_KEYUP: if this value is specified, the key is released. If this value is not specified, the key is handed over. DwExtralnfo: defines the 32-bit value associated with the strike key.

Return Value: this function has no return value.

Note: Although keybd_event transmits an OEM-related hardware scan code to the system, the application cannot use this scan code. The system internally converts the scan code to a virtual key code, and clears the UP/down bits before being sent to the application. The application can obtain a screen snapshot by pressing the PRINTSCREEN key and store it in the clipboard. To do this, set the bVk parameter of keybd_event to VK_SNAPSHOT and the bScan parameter to 0 (used to obtain a full-screen snapshot) or set hScan to 1 (only get the snapshot of the active window ). Windows CE: WindowsCE supports the flag bit appended to the dwFlags parameter. That is, the KEYEVENTF_SILENT flag is used to simulate the strike key without the sound of the strike. Windows CE does not support the KEYEVENTF_EXTENDEDKEY flag.

 

Keybd_event (13, 0, 0, 0); // simulate sending a carriage return message

Related Article

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.