Windows Surface Pro上的StylusEvent

时间:2014-08-19 14:11:05

标签: c# wpf pixelsense

我正在为Windows Surface Pro开发应用程序。我需要在屏幕上收集笔压力,我想知道这样做。

在解决由于Event引起的一些问题后(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吗? 重点是:我需要收集屏幕上笔的压力(压力)。

非常感谢。

一些信息:我正在开发视觉效果tudio 2012 Ultimate,赢得7 Pc。我在带有Windows 8.1的Surface Pro中部署应用程序。我安装并配置了Surface SDK 2.0和Surface Runtime。

1 个答案:

答案 0 :(得分:0)

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

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

我发布此信息仅用于社区信息。

相关问题