我目前正在尝试开发一个触摸屏应用程序:
- Windows 7
- Visual Studio 2013
- C# - WPF
我工作的地方将安装触摸屏(实际上是放置在平面屏幕上的一层)。
我希望能够生成触摸输入,以便在没有屏幕的情况下开发和测试应用程序。
我找到的所有资源要么很旧要么很复杂。
当今在没有触摸屏的情况下开发和测试触摸屏应用程序的最佳方法是什么?
最佳答案
一种方法是将第二个鼠标连接到您的工作站。然后您可以测试多点触控(调整大小、旋转等)。几年前我设法做到了。不过,您需要合适的驱动程序。请查看 moultitouch project .我想我正在使用那个或类似的东西。
您可以在此 SuperUser post 中找到更多建议.但我从未尝试过。
编辑
查看您的评论后,我更了解您的问题。试试这个 StackOverflow thread .它正在讨论将鼠标重新路由到触摸事件中。也检查 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
}
关于c# - 如何在不使用触摸屏的情况下模拟触摸事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29489004/