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
<PackageReference Include="Net4x.InputSimulator" Version="2.2.0.26250" />
<PackageVersion Include="Net4x.InputSimulator" Version="2.2.0.26250" />
<PackageReference Include="Net4x.InputSimulator" />
paket add Net4x.InputSimulator --version 2.2.0.26250
#r "nuget: Net4x.InputSimulator, 2.2.0.26250"
#:package Net4x.InputSimulator@2.2.0.26250
#addin nuget:?package=Net4x.InputSimulator&version=2.2.0.26250
#tool nuget:?package=Net4x.InputSimulator&version=2.2.0.26250
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
VkKeyScanand 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
SendInputreports that nothing was inserted. - Focus.
SendInputtargets whatever currently has keyboard focus. The library does not activate windows for you. - Existing key state.
SendInputdoes not reset the keyboard. If the user is holding a key when you inject input, the two combine. Check withIsKeyDownAsyncwhen it matters. - Mouse input is not simulated.
MOUSEINPUT,MouseFlagandXButtonare present for completeness of the interop surface.
Licence
See the repository for licence details.
| Product | Versions 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. |
-
.NETFramework 4.5
-
net10.0-windows7.0
- No dependencies.
-
net6.0-windows7.0
- No dependencies.
-
net8.0-windows7.0
- No dependencies.
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 |