2

How can I access pen input with pressure on Windows? I am making a paint program, and had been using wintab, but wintab does not exist on my new computer. Wintab seems to be deprecated, but there are apparently some newer APIs called Windows Ink and Tablet PC.

The problem is that I cannot find documentation or an example of how to actually use a recent pen API. The API needs to be usable from a normal, unmanaged C++ desktop application. Also, I would really rather avoid UWP if possible, because I don't want to deal with "deployment" or "signing".

Where is an SDK I can download that has C/C++ headers and libraries that will give me raw pen input?

Joe
  • 2,008
  • 1
  • 17
  • 25

2 Answers2

1

I got better results using the Realtimestylus API instead of wintab. Because wintab doesn't seem to return packets frequent enough for smooth lines when drawing.

The windows RTS API gave me more information packets, thus smoother results when drawing, and also more pen information can be accessed such as tilt and pen button presses.

there's a nice small demo app using RealTimeStylus with SDL: https://backworlds.com/under-pressure/ It includes comments in the implementation, where it explains how to access raw tablet input.

The sample code contains an eventhandler class derived from the interface class IStylusSyncPlugin from rtscom.h. With this interface you can register pen and touch events using STDMETHODS, for example: STDMETHOD(StylusButtonDown){}.

To get the actual pen position in screen coordinates is a bit difficult. As you first need to get the x,y coordinates as packets, using STDMETHOD(Packets). You will also need to describe which packets you want to receive and in what order using: IRealTimeStylus::GetPacketDescriptionData().

Lastly you need to convert the X, Y input into screen-coordinates depending on the dpi, using Gdiplus::Graphics::GetDpiX()

X = dpiX * (float)pLastPacket[g_lContexts[iCtx].x] / 2540;

Y = dpiY * (float)pLastPacket[g_lContexts[iCtx].y] / 2540;

All this is provided in the example code by Anders Ekermo.

Hope it helps.

0

Look at RealTimeStylus and the MS Pointer API (WM_PointerXxx messages). These are two different ways.

Kenneth Evans
  • 2,179
  • 19
  • 26