首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何不使用触摸屏来模拟触摸事件?

如何不使用触摸屏来模拟触摸事件?
EN

Stack Overflow用户
提问于 2015-04-07 10:08:30
回答 3查看 12.9K关注 0票数 5

我目前正在尝试开发一个触摸屏应用程序,其中包括:

  • Windows 7
  • 2013
  • C# - WPF

我正在工作的地方将收到一个触摸屏(实际上是一个放置在平面屏幕上的图层)。

我希望能够生成触摸输入,以便在没有屏幕的情况下开发和测试应用程序。

我发现的所有资源,要么是相当古老的,要么是复杂的。

在没有触摸屏的情况下,开发和测试触摸屏应用程序的最佳方法是什么?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-04-07 12:00:44

一种方法是将第二个鼠标附加到您的工作站上。然后您可以测试多点触摸(调整大小、旋转等)。我几年前就做到了。不过,你需要合适的司机。请查一下触模工程。我想我是在用那个或类似的东西。

您可以在这个SuperUser邮政中找到更多建议。但我从来没试过。

编辑

在检查了你的意见后,我更了解你的问题。试试这个StackOverflow螺纹。它正在讨论将鼠标重新定位为触控事件。还检查Blake.NUI项目-它改进了WPF 4,以更好地处理触摸交互(以及其他事情)。

在该项目中,您将发现应该帮助您将鼠标转换为触摸事件的MouseTouchDevice类:

代码语言:javascript
复制
 /// <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
}
票数 6
EN

Stack Overflow用户

发布于 2015-04-07 11:49:15

我在win 8的开发者预览版中使用了,它支持单点触摸、缩放手势和旋转手势。

票数 1
EN

Stack Overflow用户

发布于 2016-01-09 22:44:28

我知道如何在Windows 7中这样做的唯一方法(不会被视为“黑客”)是创建一个HID数字化驱动程序,然后向该驱动程序发送报告消息,这将告诉Windows以指定的方式创建触摸事件。

然而,从Windows 8开始,触摸API在Windows中是可用的,这样可以更容易地模拟这些事情。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29489004

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档