我目前正在尝试开发具有以下功能的触摸屏应用程序:
我正在工作的地方将要接收触摸屏(实际上是放在平面屏幕上的一层)。
我希望能够生成触摸输入,以便在没有屏幕的情况下开发和测试应用程序。
我发现的所有资源都很旧或复杂。
在没有触摸屏的情况下,当今开发和测试触摸屏应用程序的最佳方法是什么?
一种方法是将第二只鼠标连接到工作站。然后,您可以测试多点触控(调整大小,旋转等)。几年前,我设法做到了。但是,您需要适当的驱动程序。请检查moultitouch项目。我想我在用那个或类似的东西。
您可以在此SuperUser帖子中找到更多建议。但是我从来没有尝试过。
编辑
检查您的评论后,我会更好地理解您的问题。试试这个StackOverflow线程。它正在讨论将鼠标重新路由到触摸事件。还要检查Blake.NUI项目-它改进了WPF 4以更好地处理触摸交互(以及其他方面)。
在项目中,您将找到MouseTouchDevice有助于您将鼠标转换为触摸事件的类:
/// <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
}
Run Code Online (Sandbox Code Playgroud)