1

I want to prototype an interface for touchscreen so that I can record every mouse click during the user test. I suceeded in making storyboard, but failed in logging mouse click.

I looked up other questions - How do I get the current mouse screen coordinates in WPF?, How do I get the current mouse screen coordinates in WPF? - but couldn't understand how to apply those codes to .xaml or code-behind file(I got error message every trial.)

If I want to record where testers click on the canvas, how can I track coordinates and export logs to other file format?

Community
  • 1
  • 1
lordpanda
  • 11
  • 1

1 Answers1

0

A really simple example,

This will record every position the user has clicked and when :

enter image description here

<Window x:Class="WpfApplication6.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
        Width="525"
        Height="350"
        MouseDown="MainWindow_OnMouseDown">
    <Grid>
        <Button Width="75"
                Margin="5"
                HorizontalAlignment="Left"
                VerticalAlignment="Top"
                Click="Button_Click"
                Content="_Show log" />

    </Grid>
</Window>

Code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;

namespace WpfApplication6
{
    /// <summary>
    ///     Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly List<Tuple<DateTime, Point>> _list;

        public MainWindow()
        {
            InitializeComponent();
            _list = new List<Tuple<DateTime, Point>>();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            IEnumerable<string> @select = _list.Select(s => string.Format("{0} {1}", s.Item1.TimeOfDay, s.Item2));
            string @join = string.Join(Environment.NewLine, @select);
            MessageBox.Show(join);
        }

        private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            Point position = e.GetPosition((IInputElement) sender);
            var tuple = new Tuple<DateTime, Point>(DateTime.Now, position);
            _list.Add(tuple);
        }
    }
}
aybe
  • 15,516
  • 9
  • 57
  • 105