gpt4 book ai didi

windows-8 - 检测 Windows 8 设备中的移动或晃动

转载 作者:行者123 更新时间:2023-12-04 05:33:54 27 4
gpt4 key购买 nike

在 Windows 8 Metro 中 - 鉴于它旨在用于平板电脑,是否可以检测到设备是否被摇晃或移动?

This文章似乎没有涵盖设备移动。

如果这是可能的,那么是否有任何在线教程或代码片段可用?

最佳答案

我认为您正在寻找 acceleromator . Example .

using Windows.UI.Core;
using Windows.Devices.Sensors;

namespace AccelerometerCS
{

partial class BlankPage
{
// Sensor and dispatcher variables
private Accelerometer _accelerometer;

// This event handler writes the current accelerometer reading to
// the three acceleration text blocks on the app's main page.

private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
{
Dispatcher.InvokeAsync(CoreDispatcherPriority.Normal, (s, a) =>
{
AccelerometerReading reading = (a.Context as AccelerometerReadingChangedEventArgs).Reading;
txtXAxis.Text = String.Format("{0,5:0.00}", reading.AccelerationX);
txtYAxis.Text = String.Format("{0,5:0.00}", reading.AccelerationY);
txtZAxis.Text = String.Format("{0,5:0.00}", reading.AccelerationZ);

}, this, e);
}

public BlankPage()
{
InitializeComponent();
_accelerometer = Accelerometer.GetDefault();

if (_accelerometer != null)
{
// Establish the report interval
uint minReportInterval = _accelerometer.MinimumReportInterval;
uint reportInterval = minReportInterval > 16 ? minReportInterval : 16;
_accelerometer.ReportInterval = reportInterval;

// Assign an event handler for the reading-changed event
_accelerometer.ReadingChanged += new TypedEventHandler<Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);
}

}
}
}

关于windows-8 - 检测 Windows 8 设备中的移动或晃动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12220723/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com