Plugin.Maui.InputListener
0.1.0-preview.2
See the version list below for details.
dotnet add package Plugin.Maui.InputListener --version 0.1.0-preview.2
NuGet\Install-Package Plugin.Maui.InputListener -Version 0.1.0-preview.2
<PackageReference Include="Plugin.Maui.InputListener" Version="0.1.0-preview.2" />
<PackageVersion Include="Plugin.Maui.InputListener" Version="0.1.0-preview.2" />
<PackageReference Include="Plugin.Maui.InputListener" />
paket add Plugin.Maui.InputListener --version 0.1.0-preview.2
#r "nuget: Plugin.Maui.InputListener, 0.1.0-preview.2"
#:package Plugin.Maui.InputListener@0.1.0-preview.2
#addin nuget:?package=Plugin.Maui.InputListener&version=0.1.0-preview.2&prerelease
#tool nuget:?package=Plugin.Maui.InputListener&version=0.1.0-preview.2&prerelease
Plugin.Maui.InputListener
A keyboard listener and input-control library for .NET MAUI and .NET 10. It
normalizes hardware keyboard KeyDown / KeyUp events, keyboard shortcuts and
hotkeys, mouse and pointer input, Android gamepad / D-pad controls, browser
WebAssembly input, native macOS AppKit events and Apple TV Siri Remote buttons
into InputBehavior events.
Preview version: 0.1.0-preview.2. 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.
Production-readiness plan
The requirements and implementation plan (Russian) tracks the gaps for real-world Android/Windows integration, using DimQ1Player as the reference consumer. It includes acceptance criteria, native-input validation, package release gates and a staged migration plan. Planned capabilities are not claims of current package support.
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-browser |
A browser running .NET WebAssembly with a DOM | Keyboard, mouse/wheel, touch and pen pointer events |
net10.0-tvos |
tvOS 14.2 | Hardware keyboard and Siri Remote direction/select/menu/play-pause buttons |
net10.0-macos |
macOS 12 | Native AppKit window-local keyboard and mouse/wheel input |
net10.0 |
N/A | Shared API; no native input adapter |
Android and Windows targets remain supported; Windows uses the versioned
net10.0-windows10.0.19041.0 TFM rather than adding a duplicate unversioned target.
Mac Catalyst and native macOS are separate targets with different host APIs.
MAUI does not provide browser, tvOS or native AppKit hosts: these three targets
use a plain InputBehavior event source and the adapters described below, not
PlatformBehavior<VisualElement> or UseInputListener().
Pointer and controller event types are part of the shared API. Android, browser
and native macOS capture pointer input; only Android currently captures gamepad
axes/buttons. tvOS remote buttons use the Controller event with
InputDeviceKind.Remote. Windows, iOS and Mac Catalyst remain keyboard-only.
Device support depends on what the OS delivers to the active host; this is not
raw HID access or system-wide/background keyboard interception.
Find this package: keyboard, hotkeys and remote control
Common search terms for this package include:
- .NET MAUI keyboard listener, MAUI key listener, MAUI key control, KeyDown KeyUp events, hardware keyboard input and keyboard shortcuts.
- .NET hotkeys, application hotkey registration, Ctrl+S shortcut, arrow-key navigation, key press handling and input event handling.
- MAUI mouse events, pointer input, touch input, stylus events, Android gamepad, joystick input, D-pad navigation and remote control.
- .NET WebAssembly keyboard events, browser WASM input, macOS AppKit keyboard listener, tvOS input, Apple TV remote and Siri Remote buttons.
For Russian-language searches: обработка клавиатуры .NET MAUI, события нажатия клавиш, горячие клавиши, клавиатурная навигация, управление пультом Android TV / Apple TV and ввод с клавиатуры WebAssembly. These phrases describe actual platform coverage above, not promised support for unimplemented adapters. NuGet search also uses the package description and tags; those metadata fields include the corresponding English terms.
Installation
Once the preview has been published:
dotnet add package Plugin.Maui.InputListener --version 0.1.0-preview.2
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.
Browser / WebAssembly (net10.0-browser)
Use a .NET WebAssembly browser host that supports JSImport / JSExport. This is
not a MAUI UI target and does not supply Blazor server-side keyboard interception.
Resolve or create one InputListenerService before attaching input. The normal
hotkey API and managed event ordering remain unchanged.
The package contains contentFiles/any/net10.0-browser1.0/inputListener.mjs; serve
this module as a static asset in your application. A WebAssembly host can link
the packaged/copied module into wwwroot as shown in the browser sample. The
library does not inject scripts or bypass a host's Content Security Policy.
var listener = new InputListenerService();
await using var input = new InputBehavior();
input.KeyDown += (_, e) =>
{
if (e.Key == InputKeys.Escape)
e.Handled = true;
};
await input.AttachAsync("#input-surface", "./inputListener.mjs");
Keep the behavior alive for the host/page lifetime and call DisposeAsync when
leaving. The selector must match an existing DOM element. Give that element a
tabindex or focus a child input to receive keyboard events. Relative module
URLs are resolved against document.baseURI; missing elements/modules fail
explicitly. For a custom .NET host, use runtime.runMain(...) rather than the
dotnet.run() convenience method if callbacks must remain usable after Main
returns. The browser sample demonstrates this lifetime.
Handled synchronously calls preventDefault and stopPropagation. Keyboard
identity uses physical DOM code; KeyChar uses the actual key character.
Pointer coordinates are CSS pixels relative to the attached element; wheel
delta is deltaX + deltaY in the browser's native deltaMode units. Pen input is
Stylus; cancelling a pointer publishes a release. Window blur releases held
keys. Disposal removes both element and blur listeners. Browser-reserved keys,
IME composition and the Gamepad API are not implemented by this adapter.
samples/Plugin.Maui.InputListener.Browser.Sample
is a dependency-free .NET WebAssembly SDK host, with a Ctrl+S hotkey, event log
and detach button. Publish its static assets:
dotnet publish samples\Plugin.Maui.InputListener.Browser.Sample\Plugin.Maui.InputListener.Browser.Sample.csproj -c Release -p:TargetFrameworks=net10.0-browser -o artifacts\browser-sample
Serve artifacts\browser-sample\wwwroot over HTTP with JavaScript and WebAssembly
MIME types. wasm-tools is optional for this sample's interpreted build; install
it when enabling native/AOT optimization.
Native macOS / AppKit (net10.0-macos)
The native macOS assembly has no MAUI dependency. Attach an application-local
monitor to an existing NSWindow on AppKit's main thread:
var listener = new InputListenerService();
var input = new InputBehavior();
var monitor = new MacInputMonitor(input, window);
input.KeyDown += (_, e) => Console.WriteLine(e.Key);
// Dispose monitor on the main thread when the owning window closes.
The monitor owns only its event registration, not the window or behavior.
Dispose it when the window closes. Events from other windows are ignored;
Handled suppresses forwarding only for this monitor's handled events.
Set window.AcceptsMouseMovedEvents = true if passive movement is needed.
Mouse coordinates are window-local with a bottom-left origin; scrolling retains
native line/pixel units. Modifier flags are included with key/pointer events;
standalone modifier presses and IME composition are not synthesized.
Apple TV / tvOS (net10.0-tvos)
Host content in a TvInputViewController, or subclass it and call base lifecycle
and press methods:
var listener = new InputListenerService();
var input = new InputBehavior();
var controller = new TvInputViewController(input);
input.Controller += (_, e) =>
{
if (e.Device == InputDeviceKind.Remote && e.Key == InputKeys.Select)
e.Handled = true;
};
The controller requests first-responder status when appearing and releases it
when disappearing. Hardware keyboards reuse UIKit key mapping. Keyless remote
presses become RemoteButtonDown / RemoteButtonUp; cancellation also releases
the button. Only handled presses are removed from a mixed press batch forwarded
to UIKit. Native/system focus and reserved Siri Remote buttons may limit delivery.
Remote events are not keyboard hotkeys. Game Controller axes, touch gestures on
the remote and the Siri microphone are not implemented.
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 macos tvos
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 eight library targets. Install the macos and
tvos workloads in addition to MAUI for native Apple library compilation.
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. Source-linked mapping/propagation and Node DOM tests run in CI, alongside
compile and pack checks. These are not physical-device input tests. Existing XML-documentation warnings
are not treated as errors.
CI, releases and NuGet publishing
- CI: runs on
mainpushes, pull requests and manual dispatch. Windows tests mappings and DOM input, builds all eight library targets and Android/Windows samples, publishes the browser sample, and packs an artifact; macOS compiles iOS, Mac Catalyst, native macOS and tvOS libraries. - Release and NuGet: triggered by
v*tags or manual dispatch with an existing tag. Validates that the tag exactly matches the projectVersion, packages all targets on Windows, creates a GitHub release (preview tags are prereleases), and attaches packages. - The separate
nugetjob then publishes to NuGet.org using Trusted Publishing (GitHub OIDC) and thenugetGitHub environment.NuGet/login@v1exchanges the job's OIDC token for a short-lived API key immediately before publishing. No permanentNUGET_API_KEYsecret is required. - Configure environment approvals/tag restrictions as appropriate, and enable
GitHub Actions for the repository. The workflow uses the scoped
GITHUB_TOKENfor release creation; no personal token is needed by Actions. - Without the NuGet username variable or a matching trusted publishing policy, the GitHub release still succeeds, but the NuGet job fails explicitly rather than falsely claiming publication. Configure the policy and variable, then rerun the failed jobs or manually dispatch the same tag. Duplicate package versions are skipped, not overwritten; a changed package needs a new version.
Configure NuGet Trusted Publishing
Sign in to the NuGet account that will own the package and open Trusted Publishing. Create a GitHub Actions policy with these values:
| Field | Value |
|---|---|
| Policy name (if requested) | Plugin.Maui.InputListener (a descriptive label) |
| Policy owner | Your NuGet account, or the NuGet organization that owns the package |
| Repository owner | dimq1 |
| Repository | Plugin.Maui.InputListener |
| Workflow file | release.yml (filename only, not .github/workflows/release.yml) |
| Environment | nuget |
| Package ID / glob pattern | Plugin.Maui.InputListener |
| Scopes | Allow publishing new packages for the first publication, and new package versions for subsequent releases |
Use the real GitHub repository owner if publishing from a fork. The repository, workflow filename and environment must match the actual Actions job. A policy does not create a GitHub repository or authorize a local Git push. The package ID must be available for a first publication, or owned by the selected NuGet owner for subsequent versions.
In GitHub Settings > Environments, create the nuget environment. Add an
environment variable named NUGET_USER with the NuGet.org profile username
that created the policy (not an email address or an assumed GitHub login).
Alternatively, set it as a repository variable under Settings > Secrets and
variables > Actions > Variables. For an organization-owned policy, the username
must be an active member authorized to publish its packages.
Only the publishing job receives id-token: write; the other jobs cannot request
NuGet publishing credentials. NuGet issues a temporary key valid for one hour.
If the policy is temporarily active, complete the first successful publication
within its seven-day activation window, or reactivate it on NuGet.org.
Commit and push this workflow before running it. Existing tags may still point
to an older workflow requiring an API-key secret. To release an existing tag
using the updated workflow from main, manually run Release and NuGet with
that tag, or use:
gh workflow run release.yml --repo dimq1/Plugin.Maui.InputListener --ref main -f tag=v0.1.0-preview.1
The workflow changes alone do not activate a NuGet policy or prove publication. See the NuGet Trusted Publishing documentation for account-side requirements.
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.2 -m "InputListener browser, tvOS and native macOS preview"
git push origin v0.1.0-preview.2
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 | Versions 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-browser1.0 is compatible. 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-macos26.0 is compatible. net10.0-tvos was computed. net10.0-tvos26.0 is compatible. net10.0-windows was computed. net10.0-windows10.0.19041 is compatible. |
-
net10.0
- No dependencies.
-
net10.0-android36.0
- No dependencies.
-
net10.0-browser1.0
- No dependencies.
-
net10.0-ios26.0
- No dependencies.
-
net10.0-maccatalyst26.0
- No dependencies.
-
net10.0-macos26.0
- No dependencies.
-
net10.0-tvos26.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 |