Net4x.InputSimulator 2.2.0.26250

dotnet add package Net4x.InputSimulator --version 2.2.0.26250
                    
NuGet\Install-Package Net4x.InputSimulator -Version 2.2.0.26250
                    
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="Net4x.InputSimulator" Version="2.2.0.26250" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.InputSimulator" Version="2.2.0.26250" />
                    
Directory.Packages.props
<PackageReference Include="Net4x.InputSimulator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Net4x.InputSimulator --version 2.2.0.26250
                    
#r "nuget: Net4x.InputSimulator, 2.2.0.26250"
                    
#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.
#:package Net4x.InputSimulator@2.2.0.26250
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Net4x.InputSimulator&version=2.2.0.26250
                    
Install as a Cake Addin
#tool nuget:?package=Net4x.InputSimulator&version=2.2.0.26250
                    
Install as a Cake Tool

Net4x.InputSimulator

A small, dependency-free wrapper around the Win32 SendInput API for synthesising keyboard input, plus the key-state queries that go with it.

Originally written by Michael Noonan; this package repackages it for modern .NET while keeping the classic .NET Framework target alive.

Target frameworks

net45 · net6.0-windows · net8.0-windows · net10.0-windows

Windows only: the library P/Invokes into user32.dll.

Install

dotnet add package Net4x.InputSimulator

Usage

Everything lives on the static WindowsInput.InputSimulator class.

using WindowsInput;

// Type some text into whatever has focus.
InputSimulator.SimulateTextEntry("Hello, world!");

// Press a single key.
InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);

// Hold a key down and release it later.
InputSimulator.SimulateKeyDown(VirtualKeyCode.SHIFT);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_A);
InputSimulator.SimulateKeyUp(VirtualKeyCode.SHIFT);

// CTRL+C
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C);

// CTRL+SHIFT+ESC
InputSimulator.SimulateModifiedKeyStroke(
    new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.SHIFT },
    VirtualKeyCode.ESCAPE);

// CTRL+K, CTRL+C style chords
InputSimulator.SimulateModifiedKeyStroke(
    VirtualKeyCode.CONTROL,
    new[] { VirtualKeyCode.VK_K, VirtualKeyCode.VK_C });

// Query the keyboard.
bool shiftHeld = InputSimulator.IsKeyDown(VirtualKeyCode.SHIFT);
bool shiftHeldNow = InputSimulator.IsKeyDownAsync(VirtualKeyCode.SHIFT);
bool capsLockOn = InputSimulator.IsTogglingKeyInEffect(VirtualKeyCode.CAPITAL);

API

Member Purpose
SimulateKeyDown(VirtualKeyCode) Injects a single KEYDOWN.
SimulateKeyUp(VirtualKeyCode) Injects a single KEYUP.
SimulateKeyPress(VirtualKeyCode) Injects KEYDOWN and KEYUP in one SendInput batch.
SimulateTextEntry(string) Types a string. See the notes below.
SimulateModifiedKeyStroke(...) Four overloads for one/many modifiers around one/many keys.
IsKeyDown(VirtualKeyCode) GetKeyState — the state as of the message being processed.
IsKeyDownAsync(VirtualKeyCode) GetAsyncKeyState — the physical state right now.
IsTogglingKeyInEffect(VirtualKeyCode) Whether a toggle such as Caps Lock or Num Lock is on.

The enums VirtualKeyCode, KeyboardFlag, MouseFlag, XButton and InputType mirror the constants in Winuser.h.

How SimulateTextEntry types things

  • Printable characters (U+0020 and above, including non-BMP characters via their surrogate pair) are injected as Unicode packets, so they arrive verbatim no matter which keyboard layout is active.
  • Line breaks — "\n", "\r" or the pair "\r\n" — press RETURN exactly once.
  • Other control characters below U+0020 are resolved through VkKeyScan and injected as the real keystroke, with any modifiers that keystroke needs held down around it. Tab becomes a genuine TAB keypress; BEL ("\a") becomes CTRL+G.
  • A control character the active layout cannot produce falls back to a Unicode packet.

Passing null throws ArgumentNullException; an empty string simulates nothing.

Modifier ordering

SimulateModifiedKeyStroke presses modifiers in the order given and releases them in reverse, so a key is never left stuck under another. Sequences are enumerated exactly once, so a lazily produced sequence cannot release different keys from the ones it pressed. A null sequence is treated as empty.

Things worth knowing

  • UIPI. Input can only be injected into processes at an equal or lower integrity level. A simulation aimed at an elevated window silently does nothing unless your process is elevated too; the simulation methods throw when SendInput reports that nothing was inserted.
  • Focus. SendInput targets whatever currently has keyboard focus. The library does not activate windows for you.
  • Existing key state. SendInput does not reset the keyboard. If the user is holding a key when you inject input, the two combine. Check with IsKeyDownAsync when it matters.
  • Mouse input is not simulated. MOUSEINPUT, MouseFlag and XButton are present for completeness of the interop surface.

Licence

See the repository for licence details.

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed.  net10.0-windows7.0 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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.2.0.26250 95 9/7/2026
2.2.0 257 3/31/2025