Method 1. SendKeys.SendWait()
Step 1.Add Reference
Then using it:
using System.Windows.Forms;
Step 2.Use it
SendKeys.SendWait("{Enter}");
Method 2.keybd_event()
Step 1. Using The Namespace:
Before using "[DllImport()]",We need add the name space :
using System.Runtime.InteropServices;
Wewill need some keys enum which are defined in System.Windows.Forms.keys. And before using the namespace we have to add refrence to our object.
Then using it:
using System.Windows.Forms;
Step 2.Import Dll;
Then,import the dll:
[DllImport("User32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo); const int KEYEVENTF_KEYDOWN = 0; const int KEYEVENTF_KEYUP = 0x2;
Step 3. Use it:
if We want to press "Enter",attention that "Keys" is not "key":
keybd_event((byte)Keys.Enter, 0, KEYEVENTF_KEYDOWN, 0);
and release it:
keybd_event((byte)Keys.Enter, 0, KEYEVENTF_KEYUP, 0);
转载请注明出处:http://www.cnblogs.com/ifinver/archive/2013/03/26/2983440.html(iFinVer)