WPF:有没有可能到"路线"普通的鼠标事件触摸事件在Windows 7 [英] WPF: Is there a possibility to "route" ordinary mouse events to touch events in Windows 7

查看:546
本文介绍了WPF:有没有可能到"路线"普通的鼠标事件触摸事件在Windows 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发使用C#(.NET 4.0)和WPF为Windows 7 $ B $触摸屏的应用程序B我的问题是触摸屏我可此刻的驱动程序仅会生成鼠标事件。 (制造商可惜不提供正版的Windows 7驱动程序)
所以,目前我不能够正确地做测试。

I'm currently developing a touch screen application using C# (.NET 4.0) and WPF for Windows 7. My problem is that the driver of the touch screen I have available at the moment only generates mouse events. (The manufacturer unfortunately does not provide a genuine Windows 7 driver) So, currently I'm not able to do tests properly.

有没有一种通用的方法告诉Windows 7的某一个设备应该是一个触摸设备?(虽然这 - 当然 - 只能提供单一的触摸事件)

Is there a generic way to tell Windows 7 that a certain device is supposed to be a touch device (although this -- of course -- could only provide single touch events)?

推荐答案

勾选此。
http://blakenui.codeplex.com/
有一个MouseTouchDevice.cs文件看起来像这样。它转换成普通鼠标事件,操作事件

Check this. http://blakenui.codeplex.com/. There is a MouseTouchDevice.cs file that looks like this. It converts normal mouse events to Manipulation events.

/// <summary>
/// Used to translate mouse events into touch events, enabling a unified 
/// input processing pipeline.
/// </summary>
/// <remarks>This class originally comes from Blake.NUI - http://blakenui.codeplex.com</remarks>
public class MouseTouchDevice : TouchDevice, ITouchDevice
{
    #region Class Members

    private static MouseTouchDevice device;

    public Point Position { get; set; }

    #endregion

    #region Public Static Methods

    public static void RegisterEvents(FrameworkElement root)
    {
        root.PreviewMouseDown += MouseDown;
        root.PreviewMouseMove += MouseMove;
        root.PreviewMouseUp += MouseUp;
        root.LostMouseCapture += LostMouseCapture;
        root.MouseLeave += MouseLeave;
    }

    #endregion

    #region Private Static Methods

    private static void MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (device != null &&
            device.IsActive)
        {
            device.ReportUp();
            device.Deactivate();
            device = null;
        }
        device = new MouseTouchDevice(e.MouseDevice.GetHashCode());
        device.SetActiveSource(e.MouseDevice.ActiveSource);
        device.Position = e.GetPosition(null);
        device.Activate();
        device.ReportDown();
    }

    private static void MouseMove(object sender, MouseEventArgs e)
    {
        if (device != null &&
            device.IsActive)
        {
            device.Position = e.GetPosition(null);
            device.ReportMove();
        }
    }

    private static void MouseUp(object sender, MouseButtonEventArgs e)
    {
        LostMouseCapture(sender, e);
    }

    static void LostMouseCapture(object sender, MouseEventArgs e)
    {
        if (device != null &&
            device.IsActive)
        {
            device.Position = e.GetPosition(null);
            device.ReportUp();
            device.Deactivate();
            device = null;
        }
    }

    static void MouseLeave(object sender, MouseEventArgs e)
    {
        LostMouseCapture(sender, e);
    }

    #endregion

    #region Constructors

    public MouseTouchDevice(int deviceId) :
        base(deviceId)
    {
        Position = new Point();
    }

    #endregion

    #region Overridden methods

    public override TouchPointCollection GetIntermediateTouchPoints(IInputElement relativeTo)
    {
        return new TouchPointCollection();
    }

    public override TouchPoint GetTouchPoint(IInputElement relativeTo)
    {
        Point point = Position;
        if (relativeTo != null)
        {
            point = this.ActiveSource.RootVisual.TransformToDescendant((Visual)relativeTo).Transform(Position);
        }

        Rect rect = new Rect(point, new Size(1, 1));

        return new TouchPoint(this, point, rect, TouchAction.Move);
    }

    #endregion
}



}

}

我希望这是你在找什么。

I am hoping this is what you are looking for.

这篇关于WPF:有没有可能到&QUOT;路线&QUOT;普通的鼠标事件触摸事件在Windows 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆