窗体输入模拟器提供一个基于 win32 SendInput  方法的 模拟键盘鼠标输入的.net 接口。windows 输入模拟器可用于 WPF、windows 窗体和控制台应用程序, 实现模拟任意按键。
使用Nuget添加引用
install-Package InputSimulator

示例

例子1:单一按键

public void PressTheSpacebar()
{
InputSimulator.SimulateKeyPress(VirtualKeyCode.SPACE);
}

例子2:按键按下和放开

public void ShoutHello()
{
// Simulate each key stroke
InputSimulator.SimulateKeyDown(VirtualKeyCode.SHIFT);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_H);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_E);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_L);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_L);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_O);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_1);
InputSimulator.SimulateKeyUp(VirtualKeyCode.SHIFT); // Alternatively you can simulate text entry to acheive the same end result
InputSimulator.SimulateTextEntry("HELLO!");
}

例子3:修饰按键 比如CTRL-C

public void SimulateSomeModifiedKeystrokes()
{
// CTRL-C (effectively a copy command in many situations)
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C); // You can simulate chords with multiple modifiers
// For example CTRL-K-C whic is simulated as
// CTRL-down, K, C, CTRL-up
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, new [] {VirtualKeyCode.VK_K, VirtualKeyCode.VK_C}); // You can simulate complex chords with multiple modifiers and key presses
// For example CTRL-ALT-SHIFT-ESC-K which is simulated as
// CTRL-down, ALT-down, SHIFT-down, press ESC, press K, SHIFT-up, ALT-up, CTRL-up
InputSimulator.SimulateModifiedKeyStroke(
new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.MENU, VirtualKeyCode.SHIFT },
new[] { VirtualKeyCode.ESCAPE, VirtualKeyCode.VK_K });
}

例子4:模拟文字输入

public void SayHello()
{
InputSimulator.SimulateTextEntry("Say hello!");
}

检测按键的不同状态

public void GetKeyStatus()
{
// Determines if the shift key is currently down
var isShiftKeyDown = InputSimulator.IsKeyDown(VirtualKeyCode.SHIFT); // Determines if the caps lock key is currently in effect (toggled on)
var isCapsLockOn = InputSimulator.IsTogglingKeyInEffect(VirtualKeyCode.CAPITAL);
}

摘自:http://inputsimulator.codeplex.com/

连接:http://wpfkb.codeplex.com/

inputsimulator - Windows Input Simulator的更多相关文章

  1. 与众不同 windows phone (25) - Input(输入)之捕获 UIElement 之外的触控操作, Silverlight 方式捕获手势操作, XNA 方式捕获手势操作, 多点触控

    原文:与众不同 windows phone (25) - Input(输入)之捕获 UIElement 之外的触控操作, Silverlight 方式捕获手势操作, XNA 方式捕获手势操作, 多点触 ...

  2. 与众不同 windows phone (24) - Input(输入)之软键盘类型, XNA 方式启动软键盘, UIElement 的 Touch 相关事件, 触摸涂鸦

    原文:与众不同 windows phone (24) - Input(输入)之软键盘类型, XNA 方式启动软键盘, UIElement 的 Touch 相关事件, 触摸涂鸦 [索引页][源码下载] ...

  3. 【本人译作推荐】Windows 8应用开发:C#和XAML卷(原名:Building Windows 8 Apps with C# and XAML)

    [图书推荐] 译名:Windows 8应用开发:C#和XAML卷 原名:Building Windows 8 Apps with C# and XAML   编辑推荐 国内第一本使用XAML与C#语言 ...

  4. C# 模拟Windows键盘事件

    发送键盘消息 [DllImport("user32.dll", EntryPoint = "keybd_event", SetLastError = true) ...

  5. 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令

    [源码下载] 背水一战 Windows 10 (24) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过非 ButtonBase 触发命令 作者:webabcd ...

  6. 背水一战 Windows 10 (23) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令

    [源码下载] 背水一战 Windows 10 (23) - MVVM: 通过 Binding 或 x:Bind 结合 Command 实现,通过 ButtonBase 触发命令 作者:webabcd ...

  7. windows phone listbox的点击事件

    前台 <ListBox x:Name="> <ListBox.ItemTemplate> <DataTemplate> <Grid Margin=& ...

  8. 【转】Windows Phone在隔离存储里存取图片文件

    一共两个页面,第一个为MainPage.xaml,代码如下: <!--ContentPanel - place additional content here--> <Grid x: ...

  9. Windows Phone 支持中国移动官方支付

    今天在这里与大家分享一个好消息,Windows Phone 官方支付支持中国移动(MO Payment),在此之前无论是 Windows Phone 的用户还是开发者,都知道在Windows Phon ...

随机推荐

  1. UVALive - 7269 I - Snake Carpet

    思路: 多画画就发现从五的时候可以这么填: 六的时候这么填: 七的时候这么填: 看出规律了吗? 没看出的话再画画把. #include <bits/stdc++.h> using name ...

  2. Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 7. Graph Algorithms and Implementation Techniques

    uva 10803 计算从任何一个点到图中的另一个点经历的途中必须每隔10千米 都必须有一个点然后就这样 floy 及解决了 ************************************* ...

  3. python 文件不存在时才能写入,读写模式xt

    想向一个文件中写入数据,但是前提必须是这个文件在文件系统上不存在.也就是不允许覆盖已存在的文件内容. 可以在open() 函数中使用x 模式来代替w 模式的方法来解决这个问题.比如: >> ...

  4. python之路----logging模块

    函数式简单配置 import logging logging.debug('debug message') #bug logging.info('info message') #信息 logging. ...

  5. P2880 [USACO07JAN]平衡的阵容Balanced Lineup

    P2880 [USACO07JAN]平衡的阵容Balanced Lineup RMQ RMQ模板题 静态求区间最大/最小值 (开了O2还能卡到rank9) #include<iostream&g ...

  6. 利用Python网络爬虫爬取学校官网十条标题

    利用Python网络爬虫爬取学校官网十条标题 案例代码: # __author : "J" # date : 2018-03-06 # 导入需要用到的库文件 import urll ...

  7. C++ 一串数字三位一节,用逗号隔开表示

    #include <iostream> #include <string> #include <sstream> using namespace std; stri ...

  8. VS中 Winform查看窗体内控件之间的相互关系

    视图----其他窗口----文档大纲 这样可以查看之前的窗体布局关系

  9. 【镜像地址】Maven地址列表

    1.国内OSChina提供的镜像,非常不错 <mirror> <id>CN</id> <name>OSChina Central</name> ...

  10. C# 查出数据表DataTable 清除一列中的重复项保留其他项

    http://bbs.csdn.net/topics/391085792     DataTable 老表= 新表.AsEnumerable().GroupBy(p => p["姓名& ...