![]() |
VOOZH | about |
dotnet add package WindowsInput --version 6.4.1
NuGet\Install-Package WindowsInput -Version 6.4.1
<PackageReference Include="WindowsInput" Version="6.4.1" />
<PackageVersion Include="WindowsInput" Version="6.4.1" />Directory.Packages.props
<PackageReference Include="WindowsInput" />Project file
paket add WindowsInput --version 6.4.1
#r "nuget: WindowsInput, 6.4.1"
#:package WindowsInput@6.4.1
#addin nuget:?package=WindowsInput&version=6.4.1Install as a Cake Addin
#tool nuget:?package=WindowsInput&version=6.4.1Install as a Cake Tool
WindowsInput provides simple .NET (C#) classes to capture and simulate Keyboard and mouse input using Win32's SetWindowsHook and SendInput. All of the interop is done for you and there is a simple programming model for everything.
Install-Package WindowsInput
public async Task RunNotepad() {
await WindowsInput.Simulate.Events()
//Hold Windows Key+R
.ClickChord(KeyCode.LWin, KeyCode.R).Wait(1000)
//Type "notepad"
.Click("notepad").Wait(1000)
//Press Enter
.Click(KeyCode.Return).Wait(1000)
//Type out our message.
.Click("These are your orders if you choose to accept them...")
.Click("This message will self destruct in 5 seconds.").Wait(5000)
//Hold Alt+F4
.ClickChord(KeyCode.Alt, KeyCode.F4).Wait(1000)
//Press Tab then Enter.
.Click(KeyCode.Tab, KeyCode.Return)
//Do it!
.Invoke()
;
public static void Main(){
using (var Keyboard = WindowsInput.Capture.Global.KeyboardAsync()) {
//Capture all events from the keyboard
Keyboard.KeyEvent += Keyboard_KeyEvent;
Console.ReadLine();
}
}
private static void Keyboard_KeyEvent(object sender, EventSourceEventArgs<KeyboardEvent> e) {
if(e.Data?.KeyDown?.Key == WindowsInput.Events.KeyCode.A || e.Data?.KeyUp?.Key == WindowsInput.Events.KeyCode.A) {
e.Next_Hook_Enabled = false;
}
}
This example waits for someone to type 'aaa' (three A's in a row) and then replaces the text with 'Always Ask Albert'.
public static Task Do() {
using (var Keyboard = WindowsInput.Capture.Global.KeyboardAsync()) {
var Listener = new WindowsInput.EventSources.TextSequenceEventSource(Keyboard, new WindowsInput.Events.TextClick("aaa"));
Listener.Triggered += (x, y) => Listener_Triggered(Keyboard, x, y); ;
Listener.Enabled = true;
Console.WriteLine("The keyboard is now listening for sequences. Try typing 'aaa' in notepad.");
Console.WriteLine("Press enter to quit...");
Console.ReadLine();
}
return Task.CompletedTask;
}
private static async void Listener_Triggered(IKeyboardEventSource Keyboard, object sender, WindowsInput.EventSources.TextSequenceEventArgs e) {
e.Input.Next_Hook_Enabled = false;
var ToSend = WindowsInput.Simulate.Events();
for (int i = 1; i < e.Sequence.Text.Length; i++) {
ToSend.Click(WindowsInput.Events.KeyCode.Backspace);
}
ToSend.Click("Always ask albert!");
//We suspend keyboard events because we don't want to accidently trigger a recursive loop if our
//sending text actually had 'aaa' in it.
using (Keyboard.Suspend()) {
await ToSend.Invoke();
}
}
public static Task Do() {
using (var Keyboard = WindowsInput.Capture.Global.KeyboardAsync()) {
var Listener = new WindowsInput.EventSources.KeyChordEventSource(Keyboard, new ChordClick(KeyCode.Control, KeyCode.Alt, KeyCode.Shift));
Listener.Triggered += (x, y) => Listener_Triggered(Keyboard, x, y);
Listener.Reset_On_Parent_EnabledChanged = false;
Listener.Enabled = true;
Console.WriteLine("The keyboard is now listening for chords. Try typing 'CONTROL+ALT+SHIFT' in notepad.");
Console.WriteLine("Press enter to quit...");
Console.ReadLine();
}
return Task.CompletedTask;
}
private static async void Listener_Triggered(IKeyboardEventSource Keyboard, object sender, WindowsInput.EventSources.KeyChordEventArgs e) {
var ToSend = WindowsInput.Simulate.Events();
ToSend.Click("You pressed the magic keys.");
using (Keyboard.Suspend()) {
await ToSend.Invoke();
}
}
This work is a tightly unified library that was built on the backs of the following giants:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net6.0-windows7.0 net6.0-windows7.0 is compatible. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.1 netcoreapp3.1 is compatible. |
| .NET Framework | net461 net461 is compatible. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
Showing the top 1 NuGet packages that depend on WindowsInput:
| Package | Downloads |
|---|---|
|
VolcanicArts.VRCOSC.SDK
VRCOSC's SDK for developing VRCOSC modules |
Showing the top 11 popular GitHub repositories that depend on WindowsInput:
| Repository | Stars |
|---|---|
|
Davidobot/BetterJoy
Allows the Nintendo Switch Pro Controller, Joycons and SNES controller to be used with CEMU, Citra, Dolphin, Yuzu and as generic XInput
|
|
|
Valkirie/HandheldCompanion
ControllerService
|
|
|
xenolightning/AudioSwitcher_v1
Version 1 of Audio Switcher
|
|
|
VolcanicArts/VRCOSC
A modular node-programming language, program creator, animation system, toolkit, router, and debugger made for VRChat
|
|
|
liuke-wuhan/ZuAnBot
祖安助手:英雄联盟(League Of Legends)一键喷人,LOL游戏和客户端中可用。只为反击喷子!
|
|
|
UltraStar-Deluxe/Play
Free and open source singing game with song editor for desktop and mobile
|
|
|
FireCubeStudios/Clippy
Bring back Clippy on Windows 10/11!
|
|
|
BruceQiu1996/NPhoenix
Base on Lcu api,support many functions.Let's go by read readme.md
|
|
|
Martenfur/TabletFriend
Toolbar builder for Windows tablets.
|
|
|
xiyanxy/BetterJoy_CHS
提供任天堂系列手柄与Cemu(搭配Cemuhook)、Citra、Dolphin、Yuzu等模拟器以及系统范围通用的XInput(DS4)支持,汉化定制版本
|
|
|
DiabloRun/DiabloInterface
Diablo 2 Interface for Streamers/Speedrunners
|
Added many performance and optimizations tweaks, added support .NET CORE