UWP How to detect pen button press

341 Views Asked by At

I am developing an app in UWP for Windows 10.

I would like to perform some action when the user presses a button on the Pen (e.g. eraser or barrel button).

Ideally, I would like to have an app-wide listener that is fired when the user presses e.g. the eraser button, even when the pen is "far" from the screen (e.g. 30 cm / 1 foot distance between the pen and the screen).

Is there any way to achieve this in UWP / C#?

Thanks!

2

There are 2 best solutions below

1
On

You could check the PenButtonListener Class which is newly added in the build 19041.

1
On

On latest windows 10, Windows.Devices.Input.PenButtonListener was added for this.