Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Emulate touch events without using touch screen

Tags:

c#

wpf

I'm currently trying to develop a touch screen application with:

  • Windows 7
  • Visual Studio 2013
  • C# - WPF

The place I'm working at is going to receive a touch screen (actually a layer to put on a flat screen).

I would like to be able to generate touch inputs in order to develop and test the application without the screen.

All the resources I find, are either quite old or complicated.

What is the best way today to develop and test touch screen applications, without the touch screen ?

like image 801
Sam Avatar asked Apr 07 '15 10:04

Sam


People also ask

How do you simulate a touch screen?

The Chrome Browser integrates a nice feature to simulate multiple mobile devices or a touch screen. Now close the settings and press the ESC (Escape Key) and switch to the "Emulation" Panel (2). The "Sensors" menu (3) let's you enable the "Emulate touch screen" (4) checkbox. That's it!

How do you simulate touch events?

Activate the Developer Tools with CMD+ALT+i (OSX) or F12 (Windows). Click the cog icon to open up it's settings. Then switch to the Overrides tab. Make sure Enable is checked and then activate Emulate touch events.

How do I simulate touch events in Chrome?

While on Chrome, press F12 to toggle Developer Mode. Then, you can switch between devices at the top. This will mimic touch gestures made by a real device.

How do you simulate a mouse on a touch screen?

What I need is, very simply, a true left mouse click and hold simulation by touch screen. I found I can have this if I touch the screen, hold and slightly move my finger around which can hold as long as my finger keeps moving around. If I keep my finger still on the same position, it will time out in 10 seconds.


2 Answers

One way to do it is to attach a second mouse to your work station. Then you can test multitouch (resizing, rotating, etc.). I managed to do that years ago. You need appropriate drivers though. Please check the moultitouch project. I think I was using that or something similar.

You can find more suggestions in this SuperUser post. But I never tried them.

EDIT

After checking your comments I understand your issue better. Try this StackOverflow thread. It's discussing rerouting mouse into touch events. Check also Blake.NUI project - it improves WPF 4 to better handle touch interaction (among other things).

In the project you will find MouseTouchDevice class that should help you converting mouse into touch 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
}
like image 117
PiotrWolkowski Avatar answered Nov 15 '22 05:11

PiotrWolkowski


I have used this with developer preview of win 8. It supports single touch, zoom gestures and the rotation gestures.

like image 39
Offa Avatar answered Nov 15 '22 03:11

Offa