您的位置:首页 > 其它

WPF 模拟键盘输入

2013-03-26 21:32 375 查看

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);


转载请注明出处:/article/5264347.html(iFinVer)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: