### Create and use a mouse and keyboard controller Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Creates a mouse and keyboard controller from catalog profiles and submits input states. The mouse example moves the cursor and releases buttons, while the keyboard example sends a key press and release. ```csharp using var mouse = ctx.CreateController(ctx.GetProfile("logitech-g502-hero")!, "mouse-1"); mouse.SubmitMouse(new HMMouseState { X = 25, Y = -10, Buttons = HMMouseButtons.Left }); mouse.SubmitMouse(new HMMouseState()); using var keyboard = ctx.CreateController(ctx.GetProfile("keychron-q6")!); keyboard.SubmitKeyboard(HMKeyModifiers.LeftShift, new[] { HMKey.A }); keyboard.SubmitKeyboard(HMKeyModifiers.None, ReadOnlySpan.Empty); ``` -------------------------------- ### Create virtual controller and submit gamepad state Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Initializes HIDMaestro, loads default profiles, installs the driver, creates a controller from the 'xbox-360-wired' profile, and submits a gamepad state with the A button pressed. Requires HIDMaestro 2.0.0; programs built on 1.x must migrate. ```csharp using var ctx = new HMContext(); ctx.LoadDefaultProfiles(); ctx.InstallDriver(); using var ctrl = ctx.CreateController(ctx.GetProfile("xbox-360-wired")!); ctrl.SubmitState(new HMGamepadState { Buttons = HMButton.A }); ``` -------------------------------- ### Build and run HIDMaestro commands Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Build the native driver and SDK, then run the SDK demo, test app, and utility commands. The build script is idempotent. The test app requires elevation and the verify script needs Python. ```bash # Build the native driver + companion for x64 and ARM64, then the SDK (idempotent). scripts\build_all.cmd # Minimal SDK consumer dotnet run --project example\SdkDemo # Full test app: cert + build + sign + install all automatic, requires elevation cd test dotnet build bin\Release\net10.0-windows10.0.26100.0\win-x64\HIDMaestroTest.exe emulate xbox-360-wired # Several controllers at once, any mix of profiles HIDMaestroTest.exe emulate xbox-series-xs-bt xbox-360-wired dualsense # List or search the 337 profiles HIDMaestroTest.exe list HIDMaestroTest.exe search thrustmaster # Measure input latency HIDMaestroTest.exe latency xbox-360-wired # Validate every API (XInput, DirectInput, HIDAPI/SDL3, browser, WGI, HID order) python scripts\verify.py --controllers 4 ``` -------------------------------- ### Register and use HMVRController for SteamVR Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Registers the native OpenVR driver and creates a controller for both hands. Submit per-frame state, handle haptic pulses, and get the headset pose. Registration is per user and loads at SteamVR's next start; unregistering throws InvalidOperationException if the registry cannot be updated. ```csharp HMVR.EnsureDriverRegistered(); // extracts once per content hash, registers for the calling user using var vr = new HMVRController(); // both hands appear in SteamVR vr.SubmitState(in state); // buttons, trigger/grip, stick, optional full pose - per frame vr.HapticReceived += (_, e) => ...; // every haptic pulse a VR app plays, with hand attribution var head = vr.GetHmdPose(); // the real headset pose, for head-as-input mapping ``` -------------------------------- ### Create dualsense-composite controller and use audio output/microphone Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Creates a composite USB persona for the DualSense using the 'dualsense-composite' profile. The UsbAudio.Output stream carries 4-channel 48 kHz PCM where channels 1/2 are the speaker and channels 3/4 drive haptic actuators; UsbAudio.Microphone accepts PCM for the headset microphone endpoint. The USB transport is bundled inside HIDMaestro.Core.dll and installs automatically on first creation. ```csharp using var ctrl = ctx.CreateController(ctx.GetProfile("dualsense-composite")!); ctrl.UsbAudio!.Output.FramesReceived += (out_, pcm) => { /* speaker + haptic PCM */ }; ctrl.UsbAudio.Microphone.Submit(micPcm); ``` -------------------------------- ### HIDMaestroProfileCheck command-line usage Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Checks a profile file or directory as the SDK loads it, printing each problem with its JSON path. Exit codes: 0 for clean, 1 for issues or measurement failure, 2 for usage error. --cost measures report programs and decoders on the interpreter; --register name=value starts a protocol register at a value. ```text HIDMaestroProfileCheck my-profiles\my-pad.json HIDMaestroProfileCheck --cost my-profiles ``` -------------------------------- ### Create controller with stable identity key Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Pass an identity key to CreateController to keep the same device paths across dispose, restart, reboot, and driver upgrade. If no key is passed, the controller index becomes the key. Verified for all controller families. ```csharp using var pad = ctx.CreateController(profile, "slot0"); // same paths every time ``` -------------------------------- ### Bind WinUSB and control the virtual GameCube adapter Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Creates the virtual adapter from the 'gamecube-adapter' profile, binds WinUSB to its devnode, and demonstrates per-port input, connection, and rumble output. The adapter sends nothing until a host writes 0x13, then reports all four ports every 8 ms. Ports keep their number when a controller leaves and returns; 'rumblePower' is the second USB cable. ```csharp using var adapter = ctx.CreateController(ctx.GetProfile("gamecube-adapter")!); adapter.BindWinUsb(); adapter.Ports[0].SubmitState(new HMGamepadState { Buttons = HMButton.A }); // port 1 adapter.Ports[2].Connect("wireless"); // a WaveBird on port 3 adapter.Ports[1].OutputChanged += (_, e) => { /* "rumble": 0 stop, 1 run, 2 stop hard */ }; ``` -------------------------------- ### Create composite controller and submit motion state Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Creates the switch2-pro-controller-composite persona and submits a motion state with accelerometer and gyro values. The OutputDecoded event provides rumble fields leftMotor and rightMotor. SubmitState accepts only a 24-byte state block; any other length throws ArgumentException. ```csharp using var pad = ctx.CreateController(ctx.GetProfile("switch2-pro-controller-composite")!); pad.OutputDecoded += (_, e) => { /* e.Fields["leftMotor"], e.Fields["rightMotor"] */ }; pad.SubmitState(new HMGamepadState { AccelGY = 1.0f, GyroDpsX = 100f }); ``` -------------------------------- ### Clone DualSense and add a button with HMProfileBuilder Source: https://github.com/hifihedgehog/hidmaestro/blob/master/README.md Builds a custom DualSense variant with 16 buttons using HMProfileBuilder and HidDescriptorBuilder. Preserves VID/PID and product string so Windows, Steam, and games still see a DualSense. InputReportSize sets the whole input report length on the wire, including its ID byte. ```csharp // Clone a DualSense and add a button var custom = new HMProfileBuilder() .FromProfile(ctx.GetProfile("dualsense")!) .Id("dualsense-16btn") .Descriptor(new HidDescriptorBuilder() .Gamepad() .AddStick("Left", 8).AddStick("Right", 8) .AddTrigger("Left", 8).AddTrigger("Right", 8) .AddButtons(16).AddHat() .Build()) .InputReportSize(9) .Build(); using var ctrl = ctx.CreateController(custom); ``` -------------------------------- ### Allowlist comment for one-shot snapshot with HMButton.Guide Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/testing/guide-in-test-loops.md Add an ALLOW-GUIDE: trailing comment on the same line as the HMButton.Guide reference to bypass the guard. This example shows a one-shot snapshot frame that demonstrates Guide routing without looping, avoiding continuous haptic acks. ```csharp // Single snapshot: Guide button demonstrates the 0x0400 wButtons routing // path on Xbox 360 descriptors. Not looped, so no continuous haptic ack. Buttons = HMButton.A | HMButton.Guide, // ALLOW-GUIDE: one-shot tour snapshot, not looped ``` -------------------------------- ### DriverBuilder.InstallDrivers Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Installs drivers. Runs the install policy and returns true only when it installed or upgraded, where it always returned true. ```APIDOC ## DriverBuilder.InstallDrivers() ### Description Installs drivers. Runs the install policy and returns true only when it installed or upgraded, where it always returned true. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns `true` only when it installed or upgraded. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### DriverBuilder.FullDeploy Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Performs a full deployment. Runs the install policy and never downgrades. ```APIDOC ## DriverBuilder.FullDeploy() ### Description Performs a full deployment. Runs the install policy and never downgrades. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### HIDMaestroUninstall JSON report example Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/UNINSTALL.md Example JSON report output from HIDMaestroUninstall with --json. Shows schemaVersion, status, exitCode, runningPrograms, and entries fields. ```json { "schemaVersion": 1, "preview": false, "status": "Removed", "exitCode": 0, "runningPrograms": [], "entries": [ { "kind": "driver package", "location": "oem5.inf (hidmaestro.inf)", "outcome": "Removed", "reason": null } ] } ``` -------------------------------- ### Allowlist comment for Guide-long-press handling test Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/testing/guide-in-test-loops.md Add an ALLOW-GUIDE: trailing comment on the same line as the HMButton.Guide reference to bypass the guard. This example exercises the Guide-haptic code path on purpose, with a 2-second sleep to avoid continuous haptic acks. ```csharp // Test for Guide-long-press handling specifically. ctrl.SubmitState(state with { Buttons = HMButton.Guide }); // ALLOW-GUIDE: exercising the Guide-haptic code path on purpose Thread.Sleep(2000); ``` -------------------------------- ### DriverBuilder.BuildDir Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Gets the build directory. Stages under %ProgramFiles%\HIDMaestro\Staging, checks every staged file on each call and needs an elevated process. Throws HMPayloadMissingException when the build lacks the driver for the machine's architecture, and InvalidOperationException after waiting two minutes for another program's staging prune. ```APIDOC ## DriverBuilder.BuildDir ### Description Gets the build directory. Stages under `%ProgramFiles%\HIDMaestro\Staging`, checks every staged file on each call and needs an elevated process. Throws `HMPayloadMissingException` when the build lacks the driver for the machine's architecture, and `InvalidOperationException` after waiting two minutes for another program's staging prune. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the build directory path. #### Response Example N/A ### Error Handling - Requires an elevated process. - Throws `HMPayloadMissingException` when the build lacks the driver for the machine's architecture. - Throws `InvalidOperationException` after waiting two minutes for another program's staging prune. ``` -------------------------------- ### HMProfileBuilder.DeviceModel Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Gets or sets the device model. ```APIDOC ## HMProfileBuilder.DeviceModel ### Description Gets or sets the device model. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the device model. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### HMProfileBuilder.DeviceModelFrom Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Gets or sets the device model source. ```APIDOC ## HMProfileBuilder.DeviceModelFrom ### Description Gets or sets the device model source. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the device model source. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### HMProfileBuilder.FeatureAnswers Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Gets or sets the feature answers. ```APIDOC ## HMProfileBuilder.FeatureAnswers ### Description Gets or sets the feature answers. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the feature answers. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### HMProfileBuilder.BluetoothTransport Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Gets or sets the Bluetooth transport. ```APIDOC ## HMProfileBuilder.BluetoothTransport ### Description Gets or sets the Bluetooth transport. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the Bluetooth transport. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### HMVR.EnsureDriverRegistered Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Writes the OpenVR path registry itself and runs no vrpathreg, so a driver registered while SteamVR runs loads at its next start. Throws InvalidOperationException when the registry cannot be updated or when an OpenVR folder another program owns cannot be moved aside. ```APIDOC ## HMVR.EnsureDriverRegistered ### Description Writes the OpenVR path registry itself and runs no vrpathreg, so a driver registered while SteamVR runs loads at its next start. Each failure to update the path registry is an `InvalidOperationException` with the cause inside. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - Throws `InvalidOperationException` when the registry cannot be updated, when an OpenVR folder another program owns cannot be moved aside, or when a program holds a folder or file there open while the extraction writes it (where it threw `IOException`). ``` -------------------------------- ### HMProfileBuilder.DriverPid Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Gets or sets the driver PID. ```APIDOC ## HMProfileBuilder.DriverPid ### Description Gets or sets the driver PID. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the driver PID. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### HMProfileBuilder.BluetoothVendorIdSource Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Gets or sets the Bluetooth vendor ID source. ```APIDOC ## HMProfileBuilder.BluetoothVendorIdSource ### Description Gets or sets the Bluetooth vendor ID source. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the Bluetooth vendor ID source. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### C# HMUninstall Preview and Run with Status Handling Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/UNINSTALL.md Use HMUninstall.Preview() to inspect uninstall actions without changes, and HMUninstall.Run() to perform the uninstall, optionally including USB/IP devices. Run requires elevation and throws UnauthorizedAccessException otherwise. The switch handles Blocked and Failed statuses, listing running programs or failed entries. ```csharp HMUninstallReport preview = HMUninstall.Preview(); // changes nothing HMUninstallReport report = HMUninstall.Run(); // needs elevation HMUninstallReport all = HMUninstall.Run(new HMUninstallOptions { IncludeUsbip = true }); switch (report.Status) { case HMUninstallStatus.Blocked: foreach (var p in report.RunningPrograms) Console.WriteLine($"Close {p.ImagePath ?? "process " + p.ProcessId} first."); break; case HMUninstallStatus.Failed: foreach (var e in report.Entries.Where(e => e.Outcome == HMUninstallOutcome.Failed)) Console.WriteLine($"{e.Kind} {e.Location}: {e.Reason}"); break; } ``` -------------------------------- ### Set(ushort vid, ushort pid, string label) Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/oem-name-override.md Sets a new OEM name label for the specified device, capturing the prior values of all three target registry paths into a pending record before writing. Requires an elevated process and throws UnauthorizedAccessException otherwise. ```APIDOC ## Set(ushort vid, ushort pid, string label) ### Description Sets a new OEM name label for the specified device, capturing the prior values of all three target registry paths into a pending record before writing. Requires an elevated process and throws UnauthorizedAccessException otherwise. ### Method Set ### Signature `public static void Set(ushort vid, ushort pid, string label)` ### Parameters - **vid** (ushort) - Required - Vendor ID of the device. - **pid** (ushort) - Required - Product ID of the device. - **label** (string) - Required - New OEM name label to write. ### Remarks - Captures the prior value of each of the three targets into a HIDMaestro-owned pending record, then writes the new label to all three. - Requires an elevated process; throws `UnauthorizedAccessException` without one. - The write is a two-phase operation: first capture existing values into the pending hive, then write the new label. ``` -------------------------------- ### Run the guard script check_no_guide_in_pulse.ps1 Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/testing/guide-in-test-loops.md Run the guard script from the project root. Exit 0 on pass, exit 1 on violation. Wire it into pre-commit or CI for continuous enforcement. ```powershell powershell -NoProfile -File scripts/check_no_guide_in_pulse.ps1 ``` -------------------------------- ### Registry queries to verify OEM name override Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/oem-name-override.md After running 'set', query three registry paths to confirm the override is applied: HKLM DirectInput, HKLM Joystick, and HKCU Joystick. All should show the custom label. ```text reg query "HKLM\SYSTEM\CurrentControlSet\Control\MediaProperties\PrivateProperties\DirectInput\VID_0079&PID_0006\OEM" /v "OEM Name" reg query "HKLM\SYSTEM\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM\VID_0079&PID_0006" /v OEMName reg query "HKCU\SYSTEM\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM\VID_0079&PID_0006" /v OEMName ``` -------------------------------- ### HIDMaestroUninstall command-line usage Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/UNINSTALL.md Command-line syntax for HIDMaestroUninstall.exe. Options include --preview, --yes, --include-usbip, and --json. Requires administrator rights; without them, exits with code 1. ```text HIDMaestroUninstall [--preview] [--yes] [--include-usbip] [--json] ``` -------------------------------- ### HMProfileBuilder.FromProfile Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Copies the whole profile, its model keys and `deviceModelFrom` included, where it dropped the feature table, `driverPid`, the extended reports and the protocol. ```APIDOC ## HMProfileBuilder.FromProfile ### Description Copies the whole profile, its model keys and `deviceModelFrom` included, where it dropped the feature table, `driverPid`, the extended reports and the protocol. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns a copy of the profile. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### DriverBuilder.GenerateCatalogs Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Generates catalogs. Holds the deploy lock, up to ten minutes, then throws InvalidOperationException. ```APIDOC ## DriverBuilder.GenerateCatalogs() ### Description Generates catalogs. Holds the deploy lock, up to ten minutes, then throws `InvalidOperationException`. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - Throws `InvalidOperationException` after holding the deploy lock for up to ten minutes. ``` -------------------------------- ### HIDMaestroTest CLI commands for OEM override Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/oem-name-override.md Commands to set, list, clear, and recover OEM name overrides via the HIDMaestroTest binary. Use 'set' with VID, PID, and label; 'list' to view current overrides; 'clear' to revert; 'recover' to restore orphaned records. ```text HIDMaestroTest oem set 0x0079 0x0006 "My Custom Label" HIDMaestroTest oem list HIDMaestroTest oem clear 0x0079 0x0006 HIDMaestroTest oem recover ``` -------------------------------- ### Run emulation and verification Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/INTERNALS.md Run the emulation command first, then run the verification script in a separate terminal. For multi-controller validation, pass multiple profile IDs to the emulation command and specify the controller count. ```bash HIDMaestroTest.exe emulate ``` ```bash python scripts/verify.py ``` ```bash HIDMaestroTest.exe emulate ... ``` ```bash python scripts/verify.py --controllers N ``` -------------------------------- ### HMProfile.XInput Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Reads and sets the `xinput` block. ```APIDOC ## HMProfile.XInput ### Description Reads and sets the `xinput` block. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the `xinput` block. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### HMOemNameOverride.Set Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Sets an OEM name override. Needs an elevated process. ```APIDOC ## HMOemNameOverride.Set ### Description Sets an OEM name override. Needs an elevated process. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - Requires an elevated process. ``` -------------------------------- ### HMProfileBuilder.XInput Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Reads and sets the `xinput` block. ```APIDOC ## HMProfileBuilder.XInput ### Description Reads and sets the `xinput` block. ### Method N/A (SDK property) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the `xinput` block. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### Browser gamepad sampling and reporting script Source: https://github.com/hifihedgehog/hidmaestro/blob/master/scripts/browser_check/index.html JavaScript that samples gamepad state, determines if any gamepad is 'live' (axes vary), and POSTs results to the server. Uses title-based progress markers and handles CORS by same-origin fetch. ```javascript // This page is served by scripts/browser_check/launcher.py over HTTP and // loaded by Edge/Chrome via --app=http://127.0.0.1:/. Same-origin // fetch() to /result lets us POST gamepad readings without CORS issues. // // We deliberately probe what real web pages see: same code path as // gamepad-tester.com / hardwaretester.com / PadForge web UI etc. const SERVER_URL = "/result"; const SAMPLE_COUNT = 30; const SAMPLE_INTERVAL_MS = 100; const status = document.getElementById('status'); const readings = document.getElementById('readings'); const samples = []; let gamepadEverSeen = false; // Title-based progress markers: survive even if fetch is blocked function mark(s) { document.title = 'HM:' + s; } mark('script_start'); window.addEventListener('error', e => mark('err:' + (e.message || 'unknown').slice(0, 40))); window.addEventListener('unhandledrejection', e => mark('rej:' + ((e.reason && e.reason.toString()) || 'unknown').slice(0, 40))); // Chrome requires gamepadconnected event before navigator.getGamepads() // returns non-null entries. Some browsers also require a user gesture first. window.addEventListener('gamepadconnected', (e) => { gamepadEverSeen = true; status.textContent = `Gamepad connected: ${e.gamepad.id} (index ${e.gamepad.index})`; }); window.addEventListener('gamepaddisconnected', (e) => { status.textContent = `Gamepad disconnected: index ${e.gamepad.index}`; }); function sample() { mark('sample_' + samples.length); const pads = navigator.getGamepads(); const live = []; for (const p of pads) { if (p) { live.push({ index: p.index, id: p.id, connected: p.connected, mapping: p.mapping, timestamp: p.timestamp, buttons: p.buttons.map(b => ({ pressed: b.pressed, value: b.value })), axes: Array.from(p.axes), }); } } samples.push({ t: performance.now(), pads: live }); // Update visible readings (helps debugging if launched manually) if (live.length > 0) { const p = live[0]; readings.textContent = `id: ${p.id}\nmapping: ${p.mapping}\n` + `axes: ${p.axes.map(a => a.toFixed(3)).join(', ')}\n` + `triggers: B6=${p.buttons[6]?.value.toFixed(2)} B7=${p.buttons[7]?.value.toFixed(2)}`; } if (samples.length >= SAMPLE_COUNT) { finish(); } else { setTimeout(sample, SAMPLE_INTERVAL_MS); } } function finish() { mark('finish_start'); // Compute "live" determination: at least one gamepad whose axes vary across samples const padCount = Math.max(0, ...samples.map(s => s.pads.length)); let liveCount = 0; if (padCount > 0) { for (let i = 0; i < padCount; i++) { const ax0Set = new Set(), ax1Set = new Set(); for (const s of samples) { const p = s.pads[i]; if (!p) continue; ax0Set.add(p.axes[0]?.toFixed(3)); ax1Set.add(p.axes[1]?.toFixed(3)); } if (ax0Set.size > 1 || ax1Set.size > 1) liveCount++; } } const result = { gamepadEverSeen, samples: samples.length, padCount, liveCount, finalSnapshot: samples[samples.length - 1]?.pads ?? [], }; // POST result to launcher and signal done mark('about_to_fetch'); fetch(SERVER_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(result), }).then(() => mark('fetch_ok')) .catch(e => mark('fetch_err:' + (e.message || 'unknown').slice(0, 40))) .finally(() => { document.title = 'HIDMAESTRO_BROWSER_CHECK_DONE'; status.textContent = `Done. ${liveCount}/${padCount} live gamepad(s).`; }); } // Start sampling immediately (don't wait for gamepadconnected: Chrome may // have already enumerated the gamepad before our handler ran). setTimeout(sample, 100); ``` -------------------------------- ### Clear(ushort vid, ushort pid) Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/oem-name-override.md Restores each of the three target registry paths independently from the pending record and drops the record. No-op if no prior Set is tracked. Requires an elevated process only when a record is pending. ```APIDOC ## Clear(ushort vid, ushort pid) ### Description Restores each of the three target registry paths independently from the pending record and drops the record. No-op if no prior Set is tracked. Requires an elevated process only when a record is pending. ### Method Clear ### Signature `public static void Clear(ushort vid, ushort pid)` ### Parameters - **vid** (ushort) - Required - Vendor ID of the device. - **pid** (ushort) - Required - Product ID of the device. ### Remarks - Restores each of the three targets independently from the pending record and drops the record. - No-op if no prior `Set` is tracked. - Requires an elevated process only when a record is pending; with nothing pending it returns without taking the lock. ``` -------------------------------- ### ListActive() Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/oem-name-override.md Enumerates tracked overrides for diagnostics. Takes no lock. ```APIDOC ## ListActive() ### Description Enumerates tracked overrides for diagnostics. Takes no lock. ### Method ListActive ### Signature `public static IReadOnlyList ListActive()` ### Parameters None. ### Returns - **IReadOnlyList** - List of tracked override entries. ### Remarks - Enumerates tracked overrides for diagnostics. - Takes no lock. ``` -------------------------------- ### HMProfileBuilder.Pid Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Sets the product ID. On a copy of a USB/IP persona, writes into its USB device descriptor too. A builder given no PID throws HMProfileException, a copy keeps its source's, and an explicit Pid(0) builds. ```APIDOC ## HMProfileBuilder.Pid ### Description Sets the product ID. On a copy of a USB/IP persona, writes into its USB device descriptor too. A builder given no PID throws `HMProfileException`, a copy keeps its source's, and an explicit `Pid(0)` builds. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters - **pid** (ushort) - Required - The product ID. ### Request Example N/A ### Response #### Success Response Returns the builder for chaining. #### Response Example N/A ### Error Handling - Throws `HMProfileException` when no PID is given. ``` -------------------------------- ### Initial readings message Source: https://github.com/hifihedgehog/hidmaestro/blob/master/scripts/browser_check/index.html Displayed in the readings element before any gamepad samples are taken. ```text No readings yet. ``` -------------------------------- ### HMProfileBuilder.Vid Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Sets the vendor ID. On a copy of a USB/IP persona, writes into its USB device descriptor too. A builder given no VID throws HMProfileException, a copy keeps its source's, and an explicit Vid(0) builds. ```APIDOC ## HMProfileBuilder.Vid ### Description Sets the vendor ID. On a copy of a USB/IP persona, writes into its USB device descriptor too. A builder given no VID throws `HMProfileException`, a copy keeps its source's, and an explicit `Vid(0)` builds. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters - **vid** (ushort) - Required - The vendor ID. ### Request Example N/A ### Response #### Success Response Returns the builder for chaining. #### Response Example N/A ### Error Handling - Throws `HMProfileException` when no VID is given. ``` -------------------------------- ### DriverBuilder.EnsureTestCertificate Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Creates the test certificate under the deploy lock. ```APIDOC ## DriverBuilder.EnsureTestCertificate() ### Description Creates the test certificate under the deploy lock. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### DriverBuilder.SignDrivers Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Signs drivers. Holds the deploy lock, up to ten minutes, then throws InvalidOperationException. ```APIDOC ## DriverBuilder.SignDrivers() ### Description Signs drivers. Holds the deploy lock, up to ten minutes, then throws `InvalidOperationException`. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - Throws `InvalidOperationException` after holding the deploy lock for up to ten minutes. ``` -------------------------------- ### Initial status message Source: https://github.com/hifihedgehog/hidmaestro/blob/master/scripts/browser_check/index.html Displayed in the status element before any gamepad events occur. ```text Waiting for gamepadconnected event... ``` -------------------------------- ### HMController.BindWinUsb Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Binds a WinUSB device. Throws TimeoutException when the registry ledger's lock, or v1.12.0's mutex beside it, stays held for 30 s, scaled, InvalidOperationException when the WinUSB lock stays held for two minutes, and ObjectDisposedException when the controller is disposed during the bind. ```APIDOC ## HMController.BindWinUsb ### Description Binds a WinUSB device. Throws `TimeoutException` when the registry ledger's lock, or v1.12.0's mutex beside it, stays held for 30 s, scaled, `InvalidOperationException` when the WinUSB lock stays held for two minutes, and `ObjectDisposedException` when the controller is disposed during the bind. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - Throws `TimeoutException` when the registry ledger's lock, or v1.12.0's mutex beside it, stays held for 30 s, scaled. - Throws `InvalidOperationException` when the WinUSB lock stays held for two minutes. - Throws `ObjectDisposedException` when the controller is disposed during the bind. ``` -------------------------------- ### Switch Pro Bluetooth protocol with SPI memory and outputReport rules Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/design/data-driven-devices.md Defines a protocol for the Switch Pro controller over Bluetooth, with report ID first in every command. It declares state, SPI memory segments, an input clock, and outputReport rules for the 0x01 and 0x10 command families. The 0x80 family is omitted because HidClass refuses those writes on this descriptor. ```json "protocol": { "state": [ { "name": "protocolSeen" }, { "name": "imu" }, { "name": "inputMode", "bits": 8, "initial": "0x30" } ], "memory": [ { "name": "spi", "size": "0x80000", "fill": "FF", "segments": [ { "at": "0x6020", "hex": "0000000000000040004000400000000000003B343B343B34" }, { "at": "0x603D", "hex": "000660000880000660000880000660000660" } ] } ], "input": { "channel": "input", "clock": { "periodMs": 15, "origin": "attach", "missedTick": "owe" } }, "commands": { "source": "outputReport", "replyPrefix": [ { "hex": "21" }, { "counter": "timer" }, { "hex": "91" }, { "input": "full", "bytes": "3-11" }, { "hex": "B0" } ], "rules": [ { "match": "01 .. .. .. .. .. .. .. .. .. 10", "minLength": 16, "set": { "protocolSeen": true }, "decode": "rumble", "reply": [ { "hex": "90" }, { "echo": "10-15" }, { "memory": "spi", "address": { "le32": 11 }, "length": { "byte": 15, "max": 29 } } ], "replyLength": 49 }, { "match": "01 .. .. .. .. .. .. .. .. .. 03", "set": { "protocolSeen": true }, "decode": "rumble", "store": { "inputMode": { "byte": 11, "in": ["30", "31", "3F"] } }, "reply": [ { "hex": "80" }, { "echo": "10" } ], "replyLength": 49 }, { "match": "01 .. .. .. .. .. .. .. .. .. 40", "set": { "protocolSeen": true }, "decode": "rumble", "store": { "imu": { "byte": 11, "nonzero": true } }, "reply": [ { "hex": "80" }, { "echo": "10" } ], "replyLength": 49 }, { "match": "01", "minLength": 11, "set": { "protocolSeen": true }, "decode": "rumble", "reply": [ { "hex": "80" }, { "echo": "10" } ], "replyLength": 49 }, { "match": "01", "set": { "protocolSeen": true } }, { "match": "10", "decode": "rumble" } ] }, "counters": [ { "name": "timer", "bits": 8, "on": "frame" } ] } ``` -------------------------------- ### HMOemNameOverride usage pattern Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/oem-name-override.md Use at consumer startup to recover orphaned overrides, then set and clear a custom label for a virtual controller. Call RecoverOrphans unconditionally at every startup to restore pre-override state after a force-kill. Set overrides the joy.cpl / DirectInput label while the virtual is live; Clear restores on clean teardown. ```csharp using HIDMaestro; // Once at consumer startup, before creating any virtuals: int recovered = HMOemNameOverride.RecoverOrphans(); using var ctx = new HMContext(); ctx.LoadDefaultProfiles(); ctx.InstallDriver(); var profile = ctx.GetProfile("generic-dinput-gamepad")!; using var ctrl = ctx.CreateController(profile); // Override joy.cpl / DirectInput label while the virtual is live HMOemNameOverride.Set(profile.VendorId, profile.ProductId, "My Custom Label"); // ... run ... // Restore on clean teardown HMOemNameOverride.Clear(profile.VendorId, profile.ProductId); ``` -------------------------------- ### Run latency benchmark for xbox-360-wired controller Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/testing/latency.md Reproduce the end-to-end input latency benchmark for a single emulated xbox-360-wired controller. The harness toggles the A button for 10,000 iterations and measures from HMController.SubmitState to XInputGetState detection. ```text HIDMaestroTest.exe latency xbox-360-wired ``` -------------------------------- ### Triton IMU storeRecord rule for SET_SETTINGS_VALUES Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/design/data-driven-devices.md Configures a protocol rule that scans SET_SETTINGS_VALUES messages on feature report 1 for the IMU setting (0x30). The rule uses storeRecord to parse packed 3-byte records and stores the 16-bit little-endian imuMode value. The IMU remains off until a host enables it. ```json "protocol": { "state": [ { "name": "imuMode", "bits": 16, "initial": "0" } ], "commands": { "source": "setReport", "rules": [ { "match": "01 87", "storeRecord": { "at": 3, "size": 3, "count": { "byte": 2, "divideBy": 3 }, "key": { "offset": 0, "value": "30" }, "store": { "imuMode": { "offset": 1, "bytes": 2, "order": "le" } } } } ] } } ``` -------------------------------- ### DeviceManager.RemoveDevice Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Removes a device. Takes the PnP lock, so it needs an elevated process to touch a present devnode. Can throw InvalidOperationException when another program holds the lock for ten minutes, with nothing removed. Can also throw the SWD helper's staging refusal before any wait, and leaves the device in place. ```APIDOC ## DeviceManager.RemoveDevice ### Description Removes a device. Takes the PnP lock, so it needs an elevated process to touch a present devnode. Can throw `InvalidOperationException` when another program holds the lock for ten minutes, with nothing removed. Can also throw the SWD helper's staging refusal before any wait, and leaves the device in place. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - Requires an elevated process to touch a present devnode. - Throws `InvalidOperationException` when another program holds the lock for ten minutes, with nothing removed. - Can throw the SWD helper's staging refusal before any wait, and leaves the device in place. ``` -------------------------------- ### Run regression battery with -Exe for non-default exe Source: https://github.com/hifihedgehog/hidmaestro/blob/master/test/regression/README.md Point the battery at a non-default executable, e.g. a published build of HIDMaestroTest.exe. ```powershell ./test/regression/regression_battery.ps1 -Exe C:\path\to\HIDMaestroTest.exe ``` -------------------------------- ### HMProfileBuilder.ClearDeviceModel Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Clears the device model. ```APIDOC ## HMProfileBuilder.ClearDeviceModel ### Description Clears the device model. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response Returns the builder for chaining. #### Response Example N/A ### Error Handling - No explicit error handling documented. ``` -------------------------------- ### Switch 2 Pro composite inputReports JSON sketch Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/design/data-driven-devices.md Sketch for the Switch 2 Pro composite device's inputReports configuration, showing the full 'bits' list carries the 21 moves of Switch2ProDevice.cs:502-527. The JSON defines two report programs ('pro' and 'common') that send on the clock, using counters, constants, copies, pack12, and conditional operations. ```json "inputReports": [ { "name": "pro", "reportId": "0x09", "size": 64, "while": "selectedReport==0x09", "send": "clock", "program": [ { "counter": "reportsSent", "at": 1, "width": 8 }, { "const": { "2": "25" } }, { "copy": "0-1", "to": 3 }, { "copy": "2", "to": 5, "mask": "1F" }, { "pack12": [4, 6], "to": 6 }, { "pack12": [8, 10], "to": 9 }, { "const": { "12": "30" } }, { "when": "featureEnabled&0x20", "ops": [ { "const": { "12": "38" } } ] } ] }, { "name": "common", "reportId": "0x05", "size": 64, "while": "selectedReport==0x05", "send": "clock", "program": [ { "counter": "reportsSent", "at": 1, "width": 32, "scale": 4 }, { "bits": [ [2, 40], [3, 41], [0, 42], [1, 43], [4, 46], [5, 47] ] }, { "pack12": [4, 6], "to": 11 }, { "pack12": [8, 10], "to": 14 }, { "const": { "32": "D80E", "34": "20", "42": "01" } }, { "when": "featureEnabled&0x04", "ops": [ { "counter": "reportsSent", "at": 43, "width": 32, "scale": 4000, "add": 1 }, { "copy": "12-23", "to": 49 } ] } ] } ] ``` -------------------------------- ### HMOemNameOverride.Clear Source: https://github.com/hifihedgehog/hidmaestro/blob/master/docs/MIGRATION.md Clears an OEM name override. Needs an elevated process only when a record is pending; returns without one when nothing is. ```APIDOC ## HMOemNameOverride.Clear ### Description Clears an OEM name override. Needs an elevated process only when a record is pending; returns without one when nothing is. ### Method N/A (SDK method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response No return value. #### Response Example N/A ### Error Handling - Requires an elevated process only when a record is pending. ``` -------------------------------- ### Run regression battery with -Verbose Source: https://github.com/hifihedgehog/hidmaestro/blob/master/test/regression/README.md Run the battery with verbose output, printing every stdin command sent to the test app. ```powershell ./test/regression/regression_battery.ps1 -Verbose ```