5

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 ?

Muds
  • 4,006
  • 5
  • 31
  • 53
Sam
  • 341
  • 1
  • 4
  • 15

3 Answers3

6

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
}
Community
  • 1
  • 1
PiotrWolkowski
  • 8,408
  • 6
  • 48
  • 68
  • It's seems like more a hack really, but thanks for your advice. – Sam Apr 07 '15 at 12:27
  • No, it's not an official way of testing multi touch. A multi touch screen is the official way :) But it does the trick as a temporal solution while waiting for the screen. – PiotrWolkowski Apr 07 '15 at 12:41
  • Thing is even when I have the screen I would like a nice solution for generating touch events. – Sam Apr 07 '15 at 13:59
  • You mean like randomly generating touch event? Maybe I didn't understand your issue correctly. – PiotrWolkowski Apr 07 '15 at 16:35
  • Not necessarily random, just touch events. I want be able to simulate a touch event, as if it was coming from a touch screen. I need this because I haven't got acces to the screen yet. – Sam Apr 08 '15 at 06:54
  • Okay, I think I get your problem now. Please check the edits to my answer. – PiotrWolkowski Apr 08 '15 at 12:28
1

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

Offa
  • 111
  • 10
  • Thanks for the answer, didn't know about it. It's limited to single touch though, thats too limiting for my use. Also, when I try and launch it says "The current operating system version is not supported by Windows Simuator". – Sam Apr 07 '15 at 11:55
0

The only way I know of how to do this in Windows 7 (that wouldn't be considered a "hack") is to create a HID digitizer driver and then sending report messages to that driver, which would tell Windows to create the touch events in the specified manner.

However, starting in Windows 8, touch APIs are available in Windows to make it easier to simulate such things.

Chef Pharaoh
  • 2,387
  • 3
  • 27
  • 38