1

I need to write a C# WPF application to capture points on tablet PCs and I'm using an InkCanvas, but I don't find a way to selectively configure the InkCanvas to acquire only a combination of mouse, pen and touch points (for my scenario I'd only need only pen or only mouse, never touch). The solution must work from Windows XP to Windows 8.1.

I tried to write a StylusPlugin following this example but:

  • RawStylusInput.StylusDeviceId doesn't return the same values on different tablet PCs;
  • even if I'd manage to distinguish between mouse, pen and touch I can't use RawStylusInput.SetStylusPoints to drop the unneeded StylusPoints because that method doesn't accept as argument null or an empty StylusPointCollection.

This solution seems to work, but Real-Time Stylus is not so WPF-like and I'd like to use InkCanvas.

Jhack
  • 510
  • 1
  • 6
  • 20

1 Answers1

0

If you are just wanting to selectively allow just pen or just mouse interaction to the InkCanvas you can handle the PreviewMouseDown, PreviewStylusDown, and PreviewTouchDown events on the InkCanvas and set the Handled property on the EventArgs to true if you want to disable that type of input. In your case something like the following should work.

    private void InkCanvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
        if (!mouseInputEnabled)
            e.Handled = true;
    }

    private void InkCanvas_PreviewStylusDown(object sender, StylusDownEventArgs e)
    {
        if (!stylusInputEnabled)
            e.Handled = true;
    }

    private void InkCanvas_PreviewTouchDown(object sender, TouchEventArgs e)
    {
        e.Handled = true;
    }
  • 1
    I tried that approach, but when I touch the InkCanvas the Preview* events fired are, in order, PreviewStylusDown, PreviewTouchDown and PreviewMouseDown. Isn't it quite strange? – Jhack Oct 13 '14 at 11:11
  • Yeah it seems strange but it is correct. This [MSDN article](http://msdn.microsoft.com/en-us/library/ms754010(v=vs.110).aspx) will shed some light on that. In most cases you want to be able to handle the input from the user regardless of the what type of input the user is using. For this reason the events are fired off down the chain until they are handled. So far I haven't had any luck finding a way to detect what the initiating input type is. Can you explain your use case so we can possibly come up with another solution? – Eric Mattison Oct 13 '14 at 16:50
  • 2
    Considering your answer, you already understood the use case. I can add that for the pen points source from which I don't need to acquire points I don't want neither to leave any stroke on the InkCanvas, nor to record any point in the underlying code. I've probably found a solution but I need to verify it better before posting it. It requires to handle other methods for Stylus, Touch and Mouse events (e.g. MouseMove, TouchMove, StylusMove, etc.) and use `e.StylusDevice.TabletDevice.Type` to determine the real source of the event and set `e.Handled = true` when needed. – Jhack Oct 13 '14 at 18:23
  • I was curious from the standpoint of say a user why you would like to not allow Touch on the InkCanvas but Stylus and Mouse support. Touch support is more common than Stylus support so it just sounded like an interesting use case to me. – Eric Mattison Oct 13 '14 at 20:38
  • 1
    The scenario is a graphometric signature software. A customer wants only mouse support (only for test), while another one needs to prevent the use of the mouse and to avoid the user to interfere with the pen signature touching the surface with the hand by mistake. Unfortunately there is no way to explain our clients that even if we avoid unwanted touches they still need a human being which drives the signing process to check if the signature "makes sense". I mean, there's no PreviewPenisDown event ;) – Jhack Oct 13 '14 at 21:12
  • Based on what I have read I am not even sure that Windows distinguishes between a stylus or touch input. There may be something you can do if you interop down to the C++ level but nothing that I have seen. – Eric Mattison Oct 13 '14 at 23:17
  • @Jhack Thanks for hints, tracking the source of the input is a good idea. Thanks. – Puty May 04 '20 at 15:37