SilvanBauer.InputActions 1.0.1

.NET Standard 2.1
dotnet add package SilvanBauer.InputActions --version 1.0.1
NuGet\Install-Package SilvanBauer.InputActions -Version 1.0.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="SilvanBauer.InputActions" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SilvanBauer.InputActions --version 1.0.1
#r "nuget: SilvanBauer.InputActions, 1.0.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 SilvanBauer.InputActions as a Cake Addin
#addin nuget:?package=SilvanBauer.InputActions&version=1.0.1

// Install SilvanBauer.InputActions as a Cake Tool
#tool nuget:?package=SilvanBauer.InputActions&version=1.0.1

InputActions

A small class library which provides classes with methods to capture user inputs with hooks and to simulate user actions. This is made possible by using the user32.dll.

This library was created to provide an easy to use solution for capturing and making user inputs with the keyboard or the mouse. Additionally the Input Actions library also provides support for capturing xbox controller inputs.

Classes and Methods

MouseActions

MouseActions is the static class providing user input and output methods for mouse actions.

  • bool SetMousePosition(int x, int y)
  • Win32Point GetMousePosition()
  • void RightClick(int x, int y)
  • void RightDown(int x, int y)
  • void RightUp(int x, int y)
  • void MiddleClick(int x, int y)
  • void MiddleDown(int x, int y)
  • void MiddleUp(int x, int y)
  • void LeftClick(int x, int y)
  • void LeftDown(int x, int y)
  • void LeftUp(int x, int y)
  • void ScrollVerticalWheel(int x, int y, int amount)
  • void ScrollHorizonalWheel(int x, int y, int amount)
  • void AddMouseHookAction(MouseHookAction mouseHookAction)
  • void RemoveMouseHookAction(string key)
  • void UnhookMouseHook()

KeyboardActions

KeyboardActions is the static class providing user input and output methods for keyboard actions.

  • KeyState GetKey(KeyboardKey key)
  • void KeyPress(KeyboardKey key)
  • void KeyUp(KeyboardKey key)
  • void KeyDown(KeyboardKey key)
  • void AddKeyboardHookAction(KeyboardHookAction keyboardHookAction)
  • void RemoveKeyboardHookAction(string key)
  • void UnhookKeyboardHook()

Hooks

When a add hook method is used a windows hook is created and the hook action is added. With the add command the same hook will have another action registered instead of creating another hook. With the remove method a registered hook action can be removed. If the last one was removed then the hook will be unhooked. To unhook all hooks at once there is the unhook methods.

KeyboardActions.AddKeyboardHookAction(new KeyboardHookAction() {
    Key = "Test",
    Action = TestKeyboardHookAction,
    KeyboardEvent = KeyboardEvent.KeyDown
});
MouseActions.AddMouseHookAction(new MouseHookAction() {
    Key = "Test",
    Action = TestMouseHookAction
});
private void TestKeyboardHookAction(int keyCode) {
    var keyName = Enum.GetName(typeof(KeyboardKey), keyCode);
    var keyState = Enum.GetName(typeof(KeyState), KeyboardActions.GetKey(KeyboardKey.LShift));

    Trace.WriteLine(keyName != null ? keyName : keyCode.ToString());
    Trace.WriteLine(keyState);
}
private void TestMouseHookAction(int mouseAction) {
    var mouseActionName = Enum.GetName(typeof(MouseEvent), mouseAction);
    Trace.WriteLine(mouseActionName);

    KeyboardActions.KeyDown(KeyboardKey.LShift);
    KeyboardActions.KeyPress(KeyboardKey.A);
    KeyboardActions.KeyPress(KeyboardKey.B);
    KeyboardActions.KeyPress(KeyboardKey.C);
    KeyboardActions.KeyUp(KeyboardKey.LShift);
}

XInputController (Xbox Controllers)

The XInputController is a class which can be instantiated and with the Update method the current controller state of the first connected controller will be set in the XInputController instance.

GitHub: https://github.com/SilvanBauer/InputActions

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
1.0.1 260 10/20/2022
1.0.0 267 10/19/2022

Added methods for getting and manipulating keys