InputSimulatorEx 2.1.1

.NET Standard 2.1
dotnet add package InputSimulatorEx --version 2.1.1
NuGet\Install-Package InputSimulatorEx -Version 2.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="InputSimulatorEx" Version="2.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add InputSimulatorEx --version 2.1.1
#r "nuget: InputSimulatorEx, 2.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install InputSimulatorEx as a Cake Addin
#addin nuget:?package=InputSimulatorEx&version=2.1.1

// Install InputSimulatorEx as a Cake Tool
#tool nuget:?package=InputSimulatorEx&version=2.1.1

Windows Input Simulator

This is a fork of the Windows Input Simulator (WIS) project, ported from .NET Framework to .NET Standard 2.1 so it's compatible with .NET Core 5 & 6.
This project was created by michaelnoonan; I just ported it & fixed some outdated examples, you can check them out below.

What does it do?

The Windows Input Simulator provides a simple programming interface to simulate keyboard & mouse input on Windows operating systems.
It supports keystrokes with modifier keys, and abstracts all of the required interop away so you can focus on your code.

Windows Forms provides the SendKeys method which can simulate text entry, but not actual key strokes. Windows Input Simulator can be used in WPF, Windows Forms and Console Applications to synthesize or simulate any Keyboard input including Control, Alt, Shift, Tab, Enter, Space, Backspace, the Windows Key, Caps Lock, Num Lock, Scroll Lock, Volume Up/Down and Mute, Web, Mail, Search, Favorites, Function Keys, Back and Forward navigation keys, Programmable keys and any other key defined in the Virtual Key table. It provides a simple API to simulate text entry, key down, key up, key press and complex modified key strokes and chords.

How does it work?

WIS uses the win32 SendInput function via p/invoke to simulate keyboard, mouse, and hardware input.

Usage

You can install it via NuGet directly, or download the .nupkg directly on the releases page.

NuGet

Install via the commandline with:
Install-Package InputSimulatorEx

Everything is contained within the InputSimulatorEx namespace.

using InputSimulatorEx;

Examples

Example: Single key press

public void PressTheSpacebar()
{
  InputSimulator sim = new();
  sim.Keyboard.KeyPress(VirtualKeyCode.SPACE);
}

Example: Key-down and Key-up

public void ShoutHello()
{
  InputSimulator sim = new();
  // Simulate each key stroke
  sim.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
  sim.Keyboard.KeyPress(VirtualKeyCode.VK_H);
  sim.Keyboard.KeyPress(VirtualKeyCode.VK_E);
  sim.Keyboard.KeyPress(VirtualKeyCode.VK_L);
  sim.Keyboard.KeyPress(VirtualKeyCode.VK_L);
  sim.Keyboard.KeyPress(VirtualKeyCode.VK_O);
  sim.Keyboard.KeyPress(VirtualKeyCode.VK_1);
  sim.Keyboard.KeyUp(VirtualKeyCode.SHIFT);

  // Alternatively you can simulate text entry to acheive the same end result
  sim.Keyboard.SimulateTextEntry("HELLO!");
}

Example: Modified keystrokes such as CTRL-C

public void SimulateSomeModifiedKeystrokes()
{
  InputSimulator sim = new();
  // CTRL-C (effectively a copy command in many situations)
  sim.Keyboard.ModifiedKeyStroke(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
  sim.Keyboard.ModifiedKeyStroke(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
  sim.Keyboard.ModifiedKeyStroke(
    new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.MENU, VirtualKeyCode.SHIFT },
    new[] { VirtualKeyCode.ESCAPE, VirtualKeyCode.VK_K });
}

Example: Simulate text entry

public void SayHello()
{
  InputSimulator sim = new();
  sim.Keyboard.TextEntry("Say hello!");
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 416 12/22/2022
2.1.0 281 11/7/2022
2.0.0 416 8/7/2022
1.0.0 249 8/7/2022