Inputsimulator-windows Input Simulator

Source: Internet
Author: User
Tags modifiers

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.