Search code examples
pen

How Do You Implement Pen Computing via WinTab on a Surface Book?


I would like to write an application that gets pen input on a Surface Book.

The primary motivation is that the new Surface Pen Platinum advertises tilt and 4096 levels of pressure, but there is no tilt response that I can find (and probably not 4096 levels of sensitivity). I am trying to understand and document this.

The Surface Book uses an N-Trig pen instead of a Wacom pen. I notice that drawing applications like Corel Painter, Krita, and Rebelle provide the option to do either WinTab or use the Windows implementation, and seem to work either way. I am using Photoshop CS5, which is before the days of N-Trig and doesn't have any such option at all, yet still works.

The Wacom drivers are not installed on this Surface Book. In earlier days of Surface computers, you could download WinTab drivers from Microsoft that apparently solved the Photoshop problem. You can still download the drivers, and the current version of these drivers is Wintab_x64_1.0.0.20. They are dated 1-12-2015 and include two DLLs: wintab32,dll and DHid.dll. Neither of these is on this Surface Book.

I downloaded the TiltTest application from the Wacom SDK and got it to work on another computer with Wacom drivers installed and using a Wacom Pen. Having the code, I can see it is providing tilt information (both altitude and azimuth), and 1024 levels of pressure (the values go from 0 to 1023 at least). If I try to run this application on the Surface Book, it just says it cannot find wintab32.dll and does not run, even with the Microsoft wintab32.dll in the same directory as the .exe. With the Wacom wintab32.dll in the directory, it gets past that but can't find the tablet service. It is using the WM_PACKET message, which is apparently Wacom-specific.

I note that one possibility seems to be to use the WM_POINTER API. However, this apparently started with Windows 8.1 and would not have been used by Photoshop CS5.

So the question is how does Photoshop work in this environment and what are the other applications doing to implement either WinTab or something else. And how would I use this in a simple app to see if I am getting tile and what levels of pressure.


Solution

  • The answer is that it doesn't work. I was so busy testing tilt that I didn't notice there was no pressure sensitivity and a warning sign on Shape Dynamics for a brush that says "Control by pressure requires a pressure sensitive tablet". It was acting like a mouse, not a pen. I don't use Photoshop for drawing very much or I would have seen this sooner.

    Using Spy++ I determined it was getting no Wintab WT_xxx messages like WT_PACKET. (These are in the range 0x7FF0 to 0x7FFF, the top of the WM_USER range.)

    The solution is to install the N-Trig Wintab DLLs, wintab32.dll and NHid.dll, which are available from Microsoft. After that the warning went away, and there was pressure sensitivity. In addition, Spy++ indicated the main Photoshop window is now getting WT_xxx messages.

    So, as expected, Photoshop CS5 implemented WinTab and likely doesn't know about the later APIs. N-Trig is simulating WinTab, and the N-Trig wintab32.dll has the same functions, but a different implementation.

    As far as tilt and azimuth go, The Surface Book does not provide them, even with the new Surface pen. None of the drawing applications mentioned, including Photoshop, shows tilt or azimuth. I have recently tried the same pen on a Surface Book 2 and a Surface Pro 6, and they do provide tilt and azimuth, although there does not seem to be azimuth with applications using the Real-Time Stylus (RTS) API.