问题描述
我目前正在使用 C# (.NET 4.0) 和 WPF for Windows 7 开发一个触摸屏应用程序.我的问题是我目前可用的触摸屏驱动程序只生成鼠标事件.(遗憾的是,制造商不提供正版 Windows 7 驱动程序)所以,目前我无法正确进行测试.
是否有一种通用的方法来告诉 Windows 7 某个设备应该是触摸设备(尽管这 - 当然 - 只能提供单点触摸事件)?
勾选这个.http://blakenui.codeplex.com/.有一个看起来像这样的 MouseTouchDevice.cs 文件.它将普通鼠标事件转换为操作事件.
///<总结>///用于将鼠标事件转化为触摸事件,实现统一///输入处理管道.///</总结>///<remarks>这个类最初来自 Blake.NUI - http://blakenui.codeplex.com</remarks>公共类 MouseTouchDevice : TouchDevice, ITouchDevice{#region 类成员私有静态 MouseTouchDevice 设备;公共点位置{获取;放;}#endregion#region 公共静态方法公共静态无效注册事件(框架元素根){root.PreviewMouseDown += MouseDown;root.PreviewMouseMove += MouseMove;root.PreviewMouseUp += MouseUp;root.LostMouseCapture += LostMouseCapture;root.MouseLeave += MouseLeave;}#endregion#region 私有静态方法私有静态无效 MouseDown(对象发送者,MouseButtonEventArgs e){如果(设备!= null &&设备.IsActive){device.ReportUp();设备.停用();设备=空;}device = new MouseTouchDevice(e.MouseDevice.GetHashCode());device.SetActiveSource(e.MouseDevice.ActiveSource);device.Position = e.GetPosition(null);设备.激活();device.ReportDown();}私有静态无效 MouseMove(对象发送者,MouseEventArgs e){如果(设备!= null &&设备.IsActive){device.Position = e.GetPosition(null);device.ReportMove();}}私有静态无效 MouseUp(对象发送者,MouseButtonEventArgs e){LostMouseCapture(sender, e);}静态无效 LostMouseCapture(对象发送者,MouseEventArgs e){如果(设备!= null &&设备.IsActive){device.Position = e.GetPosition(null);device.ReportUp();设备.停用();设备=空;}}静态无效 MouseLeave(对象发送者,MouseEventArgs e){LostMouseCapture(sender, e);}#endregion#region 构造函数公共 MouseTouchDevice(int deviceId):基础(设备 ID){位置 = 新点();}#endregion#region 覆盖的方法公共覆盖 TouchPointCollection GetIntermediateTouchPoints(IInputElement relativeTo){返回新的 TouchPointCollection();}公共覆盖 TouchPoint GetTouchPoint(IInputElement relativeTo){点点=位置;if (relativeTo != null){point = this.ActiveSource.RootVisual.TransformToDescendant((Visual)relativeTo).Transform(Position);}矩形 rect = new Rect(point, new Size(1, 1));return new TouchPoint(this, point, rect, TouchAction.Move);}#endregion}
}
我希望这是您正在寻找的.p>
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.
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)?
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:是否有可能“路由"?Windows 7中的普通鼠标事件触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!