Accelerometer.Shaken | shaken event

Applies to Windows and Windows Phone

Occurs when the accelerometer detects that the PC has been shaken.


function onShaken(eventArgs) { /* Your code */ }
// addEventListener syntax
accelerometer.addEventListener("shaken", onShaken);
accelerometer.removeEventListener("shaken", onShaken);
- or -

accelerometer.onshaken = onShaken;

Event information

Delegate TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs>


Use this event to receive notification that the device containing the accelerometer has been shaken. The app is not required to set a report interval prior to registering for Shaken events.

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

private void ScenarioEnable(object sender, RoutedEventArgs e)
    if (_accelerometer != null)
        Window.Current.VisibilityChanged += new WindowVisibilityChangedEventHandler(VisibilityChanged);
        _accelerometer.Shaken += new TypedEventHandler<Accelerometer, AccelerometerShakenEventArgs>(Shaken);
        ScenarioEnableButton.IsEnabled = false;
        ScenarioDisableButton.IsEnabled = true;
        rootPage.NotifyUser("No accelerometer found", NotifyType.StatusMessage);

The following example shows the Shaken event handler.

async private void Shaken(object sender, AccelerometerShakenEventArgs e)
    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        ScenarioOutputText.Text = _shakeCount.ToString();

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

function enableShakenScenario() {
    if (accelerometer) {
        document.addEventListener("msvisibilitychange", msVisibilityChangeHandler, false);
        accelerometer.addEventListener("shaken", onShaken);
        document.getElementById("scenario2Open").disabled = true;
        document.getElementById("scenario2Revoke").disabled = false;
    } else {
        WinJS.log && WinJS.log("No accelerometer found", "sample", "error");

The following example shows the Shaken event handler.

var onShaken = (function () {
    var shakeCount = 0;

    return function (e) {
        document.getElementById("shakeOutput").innerHTML = shakeCount;

Windows Phone 8:  The accelerometer sensor does not raise the Shaken event on the Windows Phone 8 platform. If you add an event handler for the Shaken event in your Windows Phone 8 app, no error is raised, but the code in the event handler won’t run.


Minimum supported client

Windows 8

Minimum supported server

None supported

Minimum supported phone

Windows Phone 8


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



See also




© 2015 Microsoft