The form input emulator provides a. NET interface that simulates keyboard mouse input based on the Win32 SendInput method. The Windows input emulator is available for WPF, Windows Forms, and console applications, enabling you to simulate any keystroke. Adding references using NuGet
Install-package Inputsimulator
Example
Example 1: Single button
Public void Pressthespacebar () { inputsimulator.simulatekeypress (virtualkeycode.space);}
Example 2: Press and release the button
Public voidShouthello () {//simulate each key strokeInputsimulator.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 can simulate text entry to acheive the same end resultInputsimulator.simulatetextentry ("hello!");}
Example 3: Modifier keys such as ctrl-c
Public voidSimulatesomemodifiedkeystrokes () {//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-upInputsimulator.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-upInputsimulator.simulatemodifiedkeystroke (New[] {virtualkeycode.control, Virtualkeycode.menu, virtualkeycode.shift},New[] {virtualkeycode.escape, virtualkeycode.vk_k});}
Example 4: Analog text input
Public void SayHello () { inputsimulator.simulatetextentry ("Say hello! " );}
Detect different states of keys
Public void Getkeystatus () { // determines if the SHIFT key is currentlydown var Isshiftkeydown = Inputsimulator.iskeydown (virtualkeycode.shift); // determines if the CAPS LOCK key is currently in effect (toggled on) var iscapslockon = inputsimulator.istogglingkeyineffect (virtualkeycode.capital);}
Excerpt from: http://inputsimulator.codeplex.com/
Connection: http://wpfkb.codeplex.com/
Inputsimulator-windows Input Simulator