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