5
votes

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 ?

3
you can raise touch events when click events happen.Raz Megrelidze
Are you talking about generating a 'WM_TOUCH' event ? If yes any resources ?Sam

3 Answers

6
votes

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
}
1
votes

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

0
votes

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.