【问题标题】:StylusEvent on Windows Surface ProWindows Surface Pro 上的触控笔事件
【发布时间】: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


    【解决方案1】:

    为了完成,我已经解决了这个问题。

    Stylus 事件(不知道如何)与 Surface SDK 冲突。一旦我从项目中删除了 SDK 引用,一切都很顺利,我解决了问题。 现在我可以正确地收集每个笔触和笔移动的压力。

    我仅发布此信息以获取社区信息。

    【讨论】:

      猜你喜欢
      • 2015-02-05
      • 2018-07-05
      • 1970-01-01
      • 1970-01-01
      • 2017-02-17
      • 2015-11-22
      • 2015-03-03
      • 1970-01-01
      • 2014-11-03
      相关资源
      最近更新 更多