Posts

Showing posts from May, 2023

WPF: How to detect if a mouse event was raised by a mouse, touch or stylus/pen input

Image
If you've ever tried to detect if a given input was caused by mouse, touch or stylus/pen, you've probably noticed that it seems easy at first - WPF provides events for mouse, touch and stylus/pen input so just use those to detect what type of input was used right? Well unfortunately it's not as simple as that - see, for compatibility reasons, touches also raise stylus/pen events and mouse events in addition to touch events and stylus/pen input also raises mouse events in addition to stylus/pen events. This means that mouse events can be caused by mouse, touch or stylus/pen input and stylus events can be caused by stylus/pen input and touch input. Luckily, the arguments passed into mouse events can be used to detect if it was caused by mouse, touch or stylus/pen input, though, finding this information can be difficult if you don't know where to look. How to detect if a mouse event was raised by mouse, touch or stylus/pen input One of the arguments passed into mouse event