Capture motion in .NET apps
Forward app-observed shakes and accelerometer samples from .NET or .NET MAUI into the session timeline.
Motion capture is opt-in. Ansight records motion your app already observes; it does not start a sensor listener or request motion permissions. The all-in-one Ansight and Ansight.Maui packages include Ansight.Motion. For a core-only integration, add Ansight.Motion separately.
Enable capture
For a native .NET app, add WithMotionCapture() to the options you use at startup:
using Ansight;
using Ansight.Motion;
var options = Options.CreateBuilder()
.WithAnsightSdk()
.WithMotionCapture()
.Build();
Runtime.InitializeAndActivate(options);
For .NET MAUI, add it inside the existing UseAnsight setup in MauiProgram.cs:
using Ansight.Maui;
using Ansight.Motion;
builder.UseAnsight<App>(options => options.WithMotionCapture());
Forward observations
Call these methods from handlers your app already owns:
MotionCapture.RecordShake();
MotionCapture.RecordAccelerometer(x, y, z); // m/s²
The accelerometer values must be in metres per second squared. If an Apple sensor API supplies values in g, multiply each axis by 9.80665 first. Calls made while Ansight is inactive or motion capture is disabled are ignored.
WithMotionCapture() enables shakes and accelerometer samples by default. Its optional configuration callback can set CaptureShake, CaptureAccelerometer, and MinimumSampleIntervalMilliseconds. The interval defaults to 20 ms and is clamped to 10–1000 ms.
The host stores motion.shake and motion.accelerometer events in motion/events.json and shows them in the session’s motion timeline. For host-injected simulator or emulator input and the shared evidence contract, see Motion Capture.