Plugin.Maui.InputListener 0.1.0-preview.1

This is a prerelease version of Plugin.Maui.InputListener.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Plugin.Maui.InputListener --version 0.1.0-preview.1
                    
NuGet\Install-Package Plugin.Maui.InputListener -Version 0.1.0-preview.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="Plugin.Maui.InputListener" Version="0.1.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Plugin.Maui.InputListener" Version="0.1.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Plugin.Maui.InputListener" />
                    
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 Plugin.Maui.InputListener --version 0.1.0-preview.1
                    
#r "nuget: Plugin.Maui.InputListener, 0.1.0-preview.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.
#:package Plugin.Maui.InputListener@0.1.0-preview.1
                    
#: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=Plugin.Maui.InputListener&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Plugin.Maui.InputListener&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Tool

Plugin.Maui.InputListener

CI NuGet

A .NET MAUI library that normalizes hardware input into InputBehavior events and provides application-wide keyboard hotkey registration.

Initial version: 0.1.0-preview.1. The API and platform coverage are still evolving. A GitHub release/package artifact does not imply publication on NuGet.org; check the NuGet package page before installing from that feed.

Platform support

Target Minimum OS Implemented native input
net10.0-android Android API 21 Keyboard, touch/stylus, mouse/wheel, gamepad/joystick axes and buttons, remote/D-pad buttons
net10.0-ios iOS 14.2 Hardware keyboard
net10.0-maccatalyst Mac Catalyst 15 Hardware keyboard
net10.0-windows10.0.19041.0 Windows 10 1809 (17763) Hardware keyboard
net10.0 N/A Shared API; no native input adapter

Pointer and controller event types are part of the shared API, but only Android currently implements their native capture. Windows, iOS and Mac Catalyst do not currently emit pointer or controller events through this plugin. Device support depends on what the OS delivers to the active view; this is not raw HID access.

Installation

Once the preview has been published:

dotnet add package Plugin.Maui.InputListener --version 0.1.0-preview.1

Before NuGet publication, download the .nupkg from a GitHub release or build it locally, then use its directory as a local NuGet source. Do not reference a .snupkg as an application dependency.

Register in MauiProgram.cs

using Microsoft.Extensions.DependencyInjection;
using Plugin.Maui.InputListener;

var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .UseInputListener();

var app = builder.Build();
// Instantiate the singleton before any behavior publishes input.
_ = app.Services.GetRequiredService<IInputListener>();
return app;

UseInputListener() registers InputListenerService and IInputListener as the same singleton. On Apple targets it also installs InputPageViewController as the PageHandler factory. Call it before creating pages; another plugin replacing that factory afterwards can prevent keyboard capture.

The DI singleton is lazy: resolve IInputListener before using its application event stream, either as above or through constructor injection. Behavior-local events do not require resolving the service.

Listen on a page

Add a behavior to a page's Behaviors collection, for example after InitializeComponent():

using Plugin.Maui.InputListener;

var input = new InputBehavior();
input.KeyDown += (_, e) =>
{
    if (e.Key == InputKeys.Escape)
        e.Handled = true;
};
input.Pointer += (_, e) =>
    System.Diagnostics.Debug.WriteLine($"{e.Device}: {e.Type} at {e.X}, {e.Y}");
input.Controller += (_, e) =>
    System.Diagnostics.Debug.WriteLine($"{e.Device}: {e.Key}, button/axis {e.Button}, value {e.Value}");
Behaviors.Add(input);

Or attach declaratively:

<ContentPage
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:input="clr-namespace:Plugin.Maui.InputListener;assembly=Plugin.Maui.InputListener"
    x:Class="MyApp.MainPage">
    <ContentPage.Behaviors>
        <input:InputBehavior KeyDown="OnKeyDown" KeyUp="OnKeyUp" />
    </ContentPage.Behaviors>
</ContentPage>
void OnKeyDown(object? sender, InputEventArgs e)
{
    if (e.Key == InputKeys.Return)
        e.Handled = true;
}

void OnKeyUp(object? sender, InputEventArgs e) { }

An attachment is not necessarily element-scoped: Windows listens on XamlRoot.Content, Android finds the outermost parent LinearLayout, and Apple targets register with the containing page controller. Prefer one behavior per page/input scope; overlapping behaviors can produce duplicate notifications. Focus and native controls can affect delivery. Android requests focus on the outer layout and observes non-clickable child views for touch, preserving native clickable-control interaction.

Application-wide hotkeys

Given an IInputListener listener resolved from the MAUI service container:

IDisposable saveRegistration = listener.RegisterHotKey(
    new HotKey(InputKeys.S, InputModifiers.Control),
    (_, e) =>
    {
        System.Diagnostics.Debug.WriteLine("Save requested");
        e.Handled = true;
    });

// When the owner is deactivated/disposed:
saveRegistration.Dispose();

Keep the returned registration for as long as the shortcut should be active. Repeated disposal is safe. Multiple handlers can register the same hotkey. Matching uses exact key and modifier equality, on KeyDown only; extra modifiers prevent a match. Hardware autorepeat can invoke a handler repeatedly.

Hotkeys receive input from attached behaviors in the running application, not system-wide/background input. Android controller/remote button events are not keyboard KeyDown events and do not trigger hotkeys. Apple Command is InputModifiers.Command; the current Windows adapter also maps the Windows modifier to Command, not to InputModifiers.Windows.

Register/unregister and process input on the UI thread: the service does not synchronize its handler dictionary or dispatch to another thread. Avoid creating additional InputListenerService instances: Current is set by its constructor.

Event model and propagation

InputBehavior exposes InputReceived, KeyDown, KeyUp, Pointer and Controller. IInputListener.InputReceived receives the shared application stream.

InputEventArgs property Meaning
Type, Device InputEventType and InputDeviceKind classifications
Key, Modifiers Normalized InputKeys and flags (Shift, Control, Alt, Command, Windows)
KeyChar Platform-derived character, generally uppercased; not a text-entry/IME API
X, Y Android pointer coordinates relative to the attached outer layout, in native pixels; gamepad motion uses the X/Y axes
Delta Sum of horizontal and vertical pointer wheel deltas
Button Native key code, mouse button flags/action button, or touch pointer ID, depending on the event
Value Sum of the Android gamepad Z/Rz axis values
Handled Mutable propagation flag; all other properties have internal setters

Fields not relevant to an event retain their default values. The public event model is not a public arbitrary-event injection API: RaiseInput is internal. The XAML InputKeysMarkupExtension and InputModifiersMarkupExtension parse enum names; modifier names can be comma-separated. There is no hotkey XAML trigger.

Delivery order is service InputReceived, matching hotkey handlers, behavior InputReceived, then the type-specific behavior event. Handled does not short-circuit those managed notifications. Native propagation is stopped where the platform adapter supports it; Apple delivery stops at the first behavior that handles the press. Handler exceptions are not swallowed by the library.

Sample application

samples/Plugin.Maui.InputListener.Sample includes a keyboard-navigable grid, File/Edit/View/Help menus, a pointer test area and an event log. Use arrows and Enter, or click/touch the grid and menus. The pointer test area depends on Android's implemented native pointer adapter.

The sample requires Android API 21+, iOS 15+, Mac Catalyst 17+, or Windows 17763+; its Apple minimums are higher than the library's.

dotnet build samples\Plugin.Maui.InputListener.Sample\Plugin.Maui.InputListener.Sample.csproj -c Release -f net10.0-android -p:TargetFrameworks=net10.0-android
dotnet build samples\Plugin.Maui.InputListener.Sample\Plugin.Maui.InputListener.Sample.csproj -c Release -f net10.0-windows10.0.19041.0 -p:TargetFrameworks=net10.0-windows10.0.19041.0

Build and package

Use the .NET SDK specified by global.json (10.0.401 with patch roll-forward), MAUI workloads, and the platform SDKs. Android application builds need the Android SDK/JDK. Apple application builds require macOS and a compatible Xcode; library compilation alone is not proof of device/runtime behavior.

dotnet workload install maui
dotnet build src\Plugin.Maui.InputListener.slnx -c Release
dotnet pack src\Plugin.Maui.InputListener.slnx -c Release -o artifacts\packages

Windows packaging includes all five library targets. Packaging on macOS excludes the conditionally included Windows target, so use Windows for the complete release package. The .nupkg includes this README; portable symbols are emitted as an adjacent .snupkg. Generated files in bin, obj and artifacts are ignored. There are currently no automated unit tests; CI performs compile and pack checks, not physical-device input tests. Existing XML-documentation warnings are not treated as errors.

CI, releases and NuGet publishing

  • CI: runs on main pushes, pull requests and manual dispatch. Windows builds all library targets, Android/Windows samples, and a package artifact; macOS compiles iOS and Mac Catalyst libraries.
  • Release and NuGet: triggered by v* tags or manual dispatch with an existing tag. Validates that the tag exactly matches the project Version, packages all targets on Windows, creates a GitHub release (preview tags are prereleases), and attaches packages.
  • The separate nuget job then publishes to NuGet.org. It uses the nuget GitHub environment and requires NUGET_API_KEY as an environment or repository secret. Configure a least-privilege NuGet API key allowed to push Plugin.Maui.InputListener, including symbols, and verify package-ID ownership on NuGet.org. Never put the key in source code.
  • Configure environment approvals/tag restrictions as appropriate, and enable GitHub Actions for the repository. The workflow uses the scoped GITHUB_TOKEN for release creation; no personal token is needed by Actions.
  • Without the NuGet secret, the GitHub release still succeeds, but the NuGet job fails explicitly rather than falsely claiming publication. Configure the secret and rerun failed jobs/manual-dispatch the same tag. Duplicate package versions are skipped, not overwritten; a changed package needs a new version.
  • NuGet trusted publishing/OIDC is not configured by this workflow. Switching to it requires a NuGet trusted-publisher policy and the corresponding workflow authentication step; do not assume it works without that external setup.

For a new release, update <Version> in the project, commit and push to main, then create the matching tag:

git tag -a v0.1.0-preview.1 -m "Initial InputListener preview"
git push origin v0.1.0-preview.1

Inspect the release workflow and the NuGet package listing before announcing publication. GitHub assets remain available independently of NuGet publication.

License and attribution

MIT. The original David Ortinau copyright notice is preserved.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-android36.0 is compatible.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-ios26.0 is compatible.  net10.0-maccatalyst was computed.  net10.0-maccatalyst26.0 is compatible.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net10.0-windows10.0.19041 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net10.0-android36.0

    • No dependencies.
  • net10.0-ios26.0

    • No dependencies.
  • net10.0-maccatalyst26.0

    • No dependencies.
  • net10.0-windows10.0.19041

    • 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
0.1.0-preview.4 87 10/7/2026
0.1.0-preview.3 81 10/7/2026
0.1.0-preview.2 76 10/7/2026
0.1.0-preview.1 72 10/7/2026