How to Detect Stylus Pen Sides (Pen Tip vs. Eraser) in WPF (C#)

Manjunath PM 0 Reputation points
2025-02-06T04:36:22.5+00:00

Hello,

I’m developing a WPF application in C# that interacts with a stylus pen on a Windows device. I need to detect which side of the stylus is being used—whether it’s the pen tip or the eraser side.

Could someone guide me on how to achieve this programmatically in WPF? Specifically:

Are there specific APIs or libraries in WPF or Windows Ink that can detect the stylus side (pen or eraser)?

If possible, I’d appreciate any code examples, documentation references, or guidance on implementing this feature in WPF.

Thank you in advance for your help!

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,824 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,289 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hongrui Yu-MSFT 4,365 Reputation points Microsoft Vendor
    2025-02-06T06:26:56.54+00:00

    Hi, @Manjunath PM. Welcome to Microsoft Q&A. 

    You could try using StylusDevice.Inverted to check whether the stylus tip or the eraser is currently being used.

    For example: Bind OnStylusMove to the StylusDown event and edit the following code

    private void OnStylusMove(object sender, StylusEventArgs e)
    {
        StylusDevice myStylusDevice = e.StylusDevice;
    
        if (myStylusDevice != null)
        {
            if (myStylusDevice.Inverted)
            {
                textbox1.Text = "stylus moves with eraser down";
            }
            else
            {
                textbox1.Text = "stylus moves with pen down";
            }
        }
    }
    

    Related Documents: StylusDevice.Inverted Property (System.Windows.Input) | Microsoft Learn


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.