How to work with Stylus Input on Windows
Hey, I'm trying to find out how to work with stylus input. Specifically I want to add stylus support to a pre-existing program (emacs). I have searched the API to get stylus input but found:
Windows Ink
https://learn.microsoft.com/en-us/windows/apps/design/input/pen-and-stylus-interactions
RealTimeStylus API
https://learn.microsoft.com/en-us/windows/win32/tablet/realtimestylus-classes-and-interfaces
Since I'm new to windows development, I'm wondering which one to use for my project. This is not strictly a C# question, as the program I'm trying to integrate with supports C code and so I would prefer to use C, however I will use C# (or even C++) if I must. Nevertheless, I'm unfamiliar with the Windows APIs so having multiple APIs to do one thing can be quite overwhelming. Which one is better to use? Also, I'm not sure which ones I can use since I have to extend a pre-existing app rather than creating a new one from scratch. I hope this question is appropriate for this channel.
Pen interactions and Windows Ink in Windows apps - Windows apps
Build Windows apps that support custom interactions from pen and stylus devices, including digital ink for natural writing and drawing experiences.
RealTimeStylus Classes and Interfaces - Win32 apps
This section contains information about the interfaces and classes used in the real time stylus.
3 Replies
Windows Ink is specifically for "Windows Apps", which you can think of like apps you get from the windows store. The easy way to tell is if you look at one of the XAML components like https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.inkcanvas?view=winrt-26100 you can see at the bottom it says what "WinRT" it applies to. A good getting started tutorial is at https://learn.microsoft.com/en-us/windows/apps/design/input/ink-walkthrough . Technically you can use these controls in Win32 apps and WPF/WinForms with https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/xaml-islands/xaml-islands
Win32 is available for desktop apps that aren't store apps. It has existed a lot longer and I'm going to guess likely what you're writing. If you don't want to use XAML Islands go with RealTimeStylus.
In the end though, it really depends on what kind of app you're writing and what the implementation you're planning is
InkCanvas Class (Windows.UI.Xaml.Controls) - Windows apps
Defines an area that receives and displays all pen input as either an ink stroke or an erase stroke (input from an eraser tip, or the pen tip when modified with an erase button).
Support ink in your Windows app - Windows apps
Learn how to support writing and drawing with Windows Ink in a basic Universal Windows Platform (UWP) app by following this step by step tutorial.
Host WinRT XAML controls in desktop apps - Windows apps
This guide helps you to create Fluent-based UWP UIs directly in your WPF and Windows Forms applications
I think the Win32 RealTimeStylus API is what I'm looking for. Do you know if there's a C API or only a C++ API?
I'm not as familiar with that. I've never done COM in C but it may be possible?