答案 0 :(得分:3)
我认为你正在寻找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);
}
}
}
}