Gyrometer.ReadingChanged | readingchanged event

Applies to Windows and Windows Phone

Occurs each time the gyrometer reports the current sensor reading.


function onReadingChanged(eventArgs) { /* Your code */ }
// addEventListener syntax
gyrometer.addEventListener("readingchanged", onReadingChanged);
gyrometer.removeEventListener("readingchanged", onReadingChanged);
- or -

gyrometer.onreadingchanged = onReadingChanged;

Event information

Delegate TypedEventHandler<Gyrometer, GyrometerReadingChangedEventArgs>


An application may register this event handler to obtain sensor readings. The application must establish a desired ReportInterval. This informs the sensor driver that resources should be allocated to satisfy the requirements of the application.

Applications can set the frequency of this event by setting the ReportInterval property.

The following example demonstrates how a Windows Store app built with C# and XAML registers its ReadingChanged event handler.

private void ScenarioEnable(object sender, RoutedEventArgs e)
    if (_gyrometer != null)
        // Establish the report interval
        _gyrometer.ReportInterval = _desiredReportInterval;

        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _gyrometer.ReadingChanged += new TypedEventHandler<Gyrometer, GyrometerReadingChangedEventArgs>(ReadingChanged);

        ScenarioEnableButton.IsEnabled = false;
        ScenarioDisableButton.IsEnabled = true;
        rootPage.NotifyUser("No gyrometer found", NotifyType.StatusMessage);

The following example shows the ReadingChanged event handler.

async private void ReadingChanged(object sender, GyrometerReadingChangedEventArgs e)
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        GyrometerReading reading = e.Reading;
        ScenarioOutput_X.Text = String.Format("{0,5:0.00}", reading.AngularVelocityX);
        ScenarioOutput_Y.Text = String.Format("{0,5:0.00}", reading.AngularVelocityY);
        ScenarioOutput_Z.Text = String.Format("{0,5:0.00}", reading.AngularVelocityZ);

The following example demonstrates how a Windows Store appbuilt with JavaScript registers its ReadingChanged event handler.

function enableReadingChangedScenario() {
    if (gyrometer) {
        // Set the reportInterval to enable the sensor events
        gyrometer.reportInterval = reportInterval;

        document.addEventListener("msvisibilitychange", msVisibilityChangeHandler, false);
        gyrometer.addEventListener("readingchanged", onDataChanged);
        document.getElementById("scenario1Open").disabled = true;
        document.getElementById("scenario1Revoke").disabled = false;
    } else {
        WinJS.log && WinJS.log("No gyrometer found", "sample", "error");

The following example shows the ReadingChanged event handler.

function onDataChanged(e) {
    var reading = e.reading;

    document.getElementById("eventOutputX").innerHTML = reading.angularVelocityX.toFixed(2);
    document.getElementById("eventOutputY").innerHTML = reading.angularVelocityY.toFixed(2);
    document.getElementById("eventOutputZ").innerHTML = reading.angularVelocityZ.toFixed(2);


Minimum supported client

Windows 8

Minimum supported server

None supported

Minimum supported phone

Windows Phone 8


Windows::Devices::Sensors [C++]



See also




© 2014 Microsoft