/shiny:shiny-gamepadfrom shiny
Generate code using Shiny.Gamepad for cross-platform game controller input - reading sticks, triggers and buttons, handling connect and disconnect, deadzones, rumble/vibration, controller battery, motion sensors and light bars, on Android, iOS, tvOS, Mac Catalyst, macOS, Windows, Linux and Blazor WebAssembly
Ships in shiny. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are an expert in Shiny.Gamepad, a cross-platform game controller library covering reading sticks, triggers and buttons, connect and disconnect, rumble, controller battery, motion sensors and light bars.
Invoke this skill when the user wants to:
Five facts decide most of the design. Getting any of them wrong produces code that looks correct and fails on real hardware.
GamepadButton.A is the
bottom face button everywhere: A on Xbox, Cross on PlayStation, B on a Nintendo pad,
whose face buttons are physically mirrored. GamepadButton.Y is the top one. Never write code
that assumes the letter matches the player's controller - use IGamepad.Kind to pick a glyph,
and nothing else.await manager.GetGamepads() has run once. That call starts the
watch. Registering the service touches no hardware at all.IGamepad.Capabilities - anything missing throws GamepadNotSupportedException.GetState() never applies one, because the right
value depends on the game. A resting thumbstick does not read zero.# every platform - Android, iOS, tvOS, Mac Catalyst, macOS, Windows, Linux (evdev), Blazor WebAssembly
dotnet add package Shiny.Gamepad
# Shiny.Gamepad.Linux / Shiny.Gamepad.Blazor no longer exist - the net10.0 build picks evdev or the
# W3C Gamepad API at runtime with OperatingSystem.IsLinux() / IsBrowser()
// every platform - MAUI, native targets, Linux, Blazor WebAssembly
builder.Services.AddGamepads();
// a server, console or test host: reports no controllers, never throws
// (on Linux, AddGamepads() would otherwise open evdev)
services.AddNotSupportedGamepads();
No permission, entitlement or manifest entry is needed on any platform.
Use both. They exist for different jobs and are derived from the same state, so they cannot disagree.
var pads = await manager.GetGamepads();
var pad = pads.FirstOrDefault();
if (pad == null)
return;
// every frame
var state = pad.GetState();
var movement = state.LeftStick.WithDeadzone(0.15f); // or state.GetMovement()
var look = state.RightStick.WithDeadzone(0.15f); // or state.GetLook()
if (state.IsPressed(GamepadButton.A))
Jump();
// IsPressed with several buttons means ALL of them - a chord
if (state.IsPressed(GamepadButton.LeftShoulder | GamepadButton.RightShoulder))
Reload();
// IsAnyPressed means either
if (state.IsAnyPressed(GamepadButton.Start | GamepadButton.Select))
OpenMenu();
Accelerate(state.RightTrigger); // 0 to 1
var direction = state.DPad; // the D-pad as a stick, so it drives the same code
GetState() never blocks and is safe to call after a disconnect - it keeps returning the last
state seen, so a render loop needs no guard.
pad.ButtonChanged += (_, e) =>
{
if (e.Button == GamepadButton.Start && e.IsPressed)
OpenMenu();
// e.State is the whole pad at that instant, for reading modifiers
if (e.Button == GamepadButton.A && e.IsPressed && e.State.IsPressed(GamepadButton.LeftShoulder))
AlternateAction();
};
pad.AxisChanged += (_, e) =>
{
if (e.Axis == GamepadAxis.LeftStickY && e.Value > 0.5f && e.PreviousValue <= 0.5f)
MoveSelectionUp();
};
One event per button, never a combined mask. Two buttons pressed in the same frame raise two events.
Threading: events are raised on whatever thread the platform delivered input on - the main thread on Android and in the browser, a background queue on Apple, the reader thread on Linux, the poll timer on Windows. Marshal before touching UI.
// MAUI
pad.ButtonChanged += (_, e) => MainThread.BeginInvokeOnMainThread(() => this.Handle(e));
manager.Connected += (_, e) => this.Assign(e.Gamepad);
manager.Disconnected += (_, e) => this.Release(e.Gamepad);
// starts the watch; Connected also fires for anything already connected
var pads = await manager.GetGamepads();
Keep the list current from the events rather than calling GetGamepads() every frame.
A disconnected IGamepad stays valid but inert: IsConnected is false, GetState() returns the
last state, and everything else throws GamepadDisconnectedException. A controller that comes
back is a new instance, not the old one revived.
// wait for the first controller - the usual opening move for a game
var pad = await manager.WaitForGamepad(ct);
// "press any button to start"
var pressed = await pad.WaitForButton(ct: ct);
var movement = state.LeftStick.WithDeadzone(0.15f);
WithDeadzone is radial (it looks at total deflection) and rescales what is left.
Never do this:
// WRONG - independent per-axis deadzone
var x = MathF.Abs(state.LeftStick.X) < 0.15f ? 0 : state.LeftStick.X;
var y = MathF.Abs(state.LeftStick.Y) < 0.15f ? 0 : state.LeftStick.Y;
That is the classic bug that makes a stick feel like it has eight directions: pushed hard up and slightly right, the X is discarded and the stick snaps to straight up.
Also never cut without rescaling - the value would jump from 0 straight to 0.15 the moment the stick left the dead area, and slow movement would be impossible.
Magnitude can slightly exceed 1 in the diagonals (most hardware reports a square range, so a
corner reads about 1.41). Clamp if that matters.
AxisChangeThresholdmanager.AxisChangeThreshold = 0.05f; // default 0.02
This is not a deadzone. It is how much an axis must move to be worth an event, measured
against the value that axis last reported - not against the previous state, so a slow sweep
still produces events. It has no effect on GetState(), which is always raw. An axis landing
exactly on centre, +1 or -1 always reports, so a stick released never leaves the player walking.
Raise it for menu navigation, lower it for a racing game's steering.
if (pad.Supports(GamepadCapabilities.Vibration))
{
// sets a LEVEL that holds until changed
await pad.SetVibration(new GamepadVibration(LowFrequency: 0.7f, HighFrequency: 0.2f));
// ... later, and do not forget this
await pad.SetVibration(GamepadVibration.Off);
}
// one-shot bump: sets the level, waits, clears it - even if cancelled
await pad.Pulse(0.8f, TimeSpan.FromMilliseconds(120));
LowFrequency is the heavy weight in the left handle - a low rumble for impacts and engines.HighFrequency is the light, fast weight in the right handle - a buzz for clicks and texture.LeftTrigger/RightTrigger need GamepadCapabilities.TriggerVibration and are ignored
rather than folded into the handles when unsupported.Always stop the motors. A controller left rumbling keeps going after the app is backgrounded on some platforms.
if (pad.Supports(GamepadCapabilities.Battery))
{
var battery = await pad.GetBattery();
// battery.Level is 0-1 or null; battery.State is Charging/Discharging/Full/Wired/Unknown
}
if (pad.Supports(GamepadCapabilities.Motion))
{
await pad.SetMotionEnabled(true); // OFF by default everywhere - sensors cost battery
pad.MotionChanged += (_, e) => Aim(e.Motion.AngularVelocityX, e.Motion.AngularVelocityY);
var latest = pad.GetMotion(); // polling counterpart, null until a sample arrives
await pad.SetMotionEnabled(false); // turn them off when you stop reading
}
if (pad.Supports(GamepadCapabilities.Light))
await pad.SetLight(GamepadLight.FromRgb(0, 128, 255));
Battery levels are coarse - four steps is common. Treat the level as a gauge to draw, not a number to do arithmetic on. Acceleration includes gravity: a controller resting on a table reads about 1g on whichever axis points up, not zero.
pad.Name // the platform's name for it, often generic
pad.Kind // Xbox / PlayStation / Nintendo / Steam / Remote / Standard - for glyphs ONLY
pad.PlayerIndex // the slot the platform assigned, from 1, or null
pad.Id // unique among connected controllers
pad.SupportedButtons // tells "not pressed" apart from "not present"
Id only survives a reconnect where GamepadCapabilities.PersistentId is set - Windows
(NonRoamableId) and Linux (the device's MAC or serial). Apple, Android and the browser hand out a
fresh identity every connection. Never key saved per-player settings on Id without checking
that flag.
if (manager is AndroidGamepadManager android)
android.ConsumeEvents = true;
GCSupportsControllerUserInteraction to Info.plist, and list GCSupportedGameControllers.
Without them the system keeps some buttons - the Home button above all - for itself.GamepadKind.Remote: no sticks, no triggers, two buttons,
with its touch surface mapped onto the left stick so menu code works unchanged.Windows.Gaming.Input's own behaviour and cannot be opted out of.manager.PollInterval (default 16ms) applies here and nowhere else. Lower it for a game
rendering above 60Hz; a poll slower than the frame rate shows up as input lag./dev/input/event*, usually via the input group. If evtest as root
sees a controller and the app does not, that is the cause.Vibration.// tell "no Gamepad API" apart from "no gesture yet"
if (manager is BlazorGamepadManager blazor)
{
var probe = await blazor.Probe();
if (!probe.Supported)
ShowUnsupportedBrowserMessage();
}
vibrationActuator - Chrome and Edge have it, Firefox and Safari do not.PollInterval is ignored - the loop is paced by requestAnimationFrame.var pads = await manager.GetGamepads();
// PlayerIndex is the platform's opinion and is null on Windows and in the browser
var p1 = await manager.GetGamepadForPlayer(1);
// assign your own slots where the platform assigns none
var assignments = new Dictionary<string, int>();
manager.Connected += (_, e) => assignments[e.Gamepad.Id] = assignments.Count + 1;
manager.Disconnected += (_, e) => assignments.Remove(e.Gamepad.Id);
| Mistake | What happens | Do instead |
|---|---|---|
Assuming GamepadButton.A is the button labelled A | Nintendo players press the wrong button | It is always the bottom face button; use Kind for glyphs |
| Per-axis deadzone | Stick snaps to eight directions | stick.WithDeadzone(0.15f) - radial |
| Cutting a deadzone without rescaling | Stick jumps; no slow movement | WithDeadzone rescales for you |
Using raw GetState() sticks for movement | Character drifts at rest | Apply a deadzone |
Calling GetGamepads() every frame | Allocates a list per frame | Call once; track via Connected/Disconnected |
Never calling GetGamepads() | No controllers, no events, ever | It starts the watch |
SetVibration without ever stopping | Controller buzzes indefinitely | GamepadVibration.Off, or Pulse |
Saving settings against Id | Bindings lost on reconnect | Check GamepadCapabilities.PersistentId first |
Calling a feature without checking Capabilities | GamepadNotSupportedException | pad.Supports(...) first |
Touching UI from ButtonChanged | Cross-thread crash | Marshal to the UI thread |
| "No controller found" in the browser | Misleading - it is waiting for a gesture | "Press any button on your controller" |
| Flipping stick Y | Inverted controls | Already flipped; Y is positive up |
Reusing a disconnected IGamepad | GamepadDisconnectedException | Take the new instance from Connected |
| Exception | Meaning |
|---|---|
GamepadNotSupportedException | The controller or platform lacks the capability. Carries the Capability flag and names the platform reason |
GamepadDisconnectedException | The controller went away. GetState() is exempt and keeps working |
GamepadException | Anything else - the platform refused, or a device node could not be opened |
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub shinyorg/skills --plugin shiny57 skills in this plugin
/localizegenGenerate strongly-typed localization classes from .resx resource files using Shiny.Extensions.Localization.Generator for .NET applications/shiny-accessorysetupGenerate code using Shiny.BluetoothLE.AccessorySetup - the system accessory pairing sheet for BLE devices (AccessorySetupKit on iOS 18+, CompanionDeviceManager on Android) with no MFi, no location prompt and no general Bluetooth prompt on iOS; picked accessories open as Shiny.BluetoothLE peripherals, and Android adds background presence (device appeared / disappeared) events/shiny-actorsGenerate code using Shiny.Actors — Orleans-style virtual actors without the ceremony, AOT/trim-clean, running anywhere .NET runs including .NET MAUI and Blazor WebAssembly. Covers actor interfaces and source-generated proxies, the ShinyActorBuilder (AddShinyActors), persistent state with ETags, named states and auto-save, event-sourced JournaledActor with snapshots, state and event migrations, typed streams (durable, implicit consumers), timers and persistent reminders (background jobs via Shiny.Jobs, on-time OS notifications via Shiny.Notifications), concurrency control ([Reentrant], [AlwaysInterleave], [ReadOnly], [StatelessWorker]), call filters and request context, OpenTelemetry traces and metrics, remoting over HTTP (Shiny.Net.HttpServer server, RemoteActorSystem client), mDNS discovery of actor servers, Shiny.DocumentDb storage (SQLite, PostgreSQL, IndexedDB...), and the ActorTestHost testing kit.Other plugins' skills for the same job