InputSimulatorEx 2.1.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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
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 6,571 12/22/2022
2.1.0 419 11/7/2022
2.0.0 626 8/7/2022
1.0.0 378 8/7/2022