【发布时间】:2014-08-19 14:11:05
【问题描述】:
我正在为 Windows Surface Pro 开发应用程序。我需要收集屏幕上的笔压,我想办法。
由于事件(StylusDown、StylusUp 和其他 Stylus 事件从未引发,仅鼠标事件)解决了一些问题后,我找到了解决方法。
我会给你看代码(取自一些微软指南) 基本上是原始事件的过滤器
class MyFilterPlugin : StylusPlugIn
{
protected override void OnStylusDown(RawStylusInput rawStylusInput)
{
// Call the base class before modifying the data.
base.OnStylusDown(rawStylusInput);
Console.WriteLine("Here");
// Restrict the stylus input.
Filter(rawStylusInput);
}
private void Filter(RawStylusInput rawStylusInput)
{
// Get the StylusPoints that have come in.
StylusPointCollection stylusPoints = rawStylusInput.GetStylusPoints();
// Modify the (X,Y) data to move the points
// inside the acceptable input area, if necessary.
for (int i = 0; i < stylusPoints.Count; i++)
{
Console.WriteLine("p: " + stylusPoints[i].PressureFactor);
StylusPoint sp = stylusPoints[i];
if (sp.X < 50) sp.X = 50;
if (sp.X > 250) sp.X = 250;
if (sp.Y < 50) sp.Y = 50;
if (sp.Y > 250) sp.Y = 250;
stylusPoints[i] = sp;
}
// Copy the modified StylusPoints back to the RawStylusInput.
rawStylusInput.SetStylusPoints(stylusPoints);
}
在 StylusPlugin 中添加为过滤器
StylusPlugIns.Add(new MyFilterPlugin());
然而,当我运行它时,我总是得到 0.5 作为 PressureFactor(默认值)并且更深入地检查我仍然可以看到 Stylus 的环境设置不正确(例如,他的 Id 为 0)。
有办法正确收集 StylusEvent 吗? 重点是:我需要收集笔在屏幕上的压力(多少压力)。
非常感谢。
一些信息:我正在使用visuals tudio 2012 Ultimate进行开发,在win 7 Pc上。我将应用程序部署在装有 Windows 8.1 的 Surface Pro 中。我安装并配置了 Surface SDK 2.0 和 Surface Runtime。
【问题讨论】:
标签: c# wpf pixelsense