WPF 模拟键盘输入

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)

转载于:https://www.cnblogs.com/ifinver/archive/2013/03/26/2983440.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值