Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you retrieve stylus pressure information on windows?

Is anyone aware of a sane way to get tablet/stylus pressure information on Windows?

It's possible to distinguish stylus from mouse with ::GetMessageExtraInfo, but you can't get any more information beyond that. I also found the WinTab API in a out of the way corner of the Wacom site, but that's not part of windows as far as i can tell, and has a completely distinct event/messaging system from the message queue.

Given all I want is the most basic pressure information surely there is a standard Win32/COM API, is anyone aware of what it might be?

like image 401
olliej Avatar asked Jan 03 '09 06:01

olliej


2 Answers

The current way to do this is to handle WM_POINTERnnn msgs. Note this is for Win 8 and later.

Note you will get these msgs for touch AND pen, so you'll need to know the pointerType in order to test for pen. The WPARAM received by a WNDPROC for WM_POINTERnnnn msgs such a WM_POINTERUPDATE and other msgs contains the pointer id which you will need in order to request more info. Empirically I found that WM_POINTERUPDATE results in info that contains pressure data whereas if the pointer flags indicate down/up there is no pressure info.

const WORD wid = GET_POINTERID_WPARAM(wParam);
POINTER_INFO piTemp = {NULL};
GetPointerInfo(wid, &piTemp);
if (piTemp.pointerType == PT_PEN
{
    UINT32 entries = 0;
    UINT32 pointers = 0;

    GetPointerFramePenInfoHistory(wid, &entries, &pointers, NULL); // how many
    // TODO, allocate space needed for the info, process the data in a loop to retrieve it, test pointerInfo.pointerFlags for down/up/update.

}

Once you know you are dealing with pen, you can get the pressure info from the POINTER_PEN_INFO struct.

This is similar to handling touch although for touch you'd want gesture recognition and inertia. There is a Microsoft sample illustrating using these functions.

It's part of a Build talk: https://channel9.msdn.com/Events/Build/2013/4-022

like image 66
kalbr Avatar answered Oct 11 '22 14:10

kalbr


You need to use the Tablet PC Pen/Ink API. The COM version of the API lives in InkObj.dll. Here is a starting point for documentation: http://msdn.microsoft.com/en-us/library/ms700664.aspx

If I remember correctly, InkObj.dll is available on Windows XP SP2 and all later Windows client OSes, regardless of whether the machine is a Tablet PC.

like image 33
Zoltan Szilagyi Avatar answered Oct 11 '22 15:10

Zoltan Szilagyi