title: Precise response to tablet/mouse events in Windows
body: <p>How can I tell Windows not to do unhelpful pre-processing on tablet pen events?</p>
  
  <p>I am programming in Python 2.6, targetting tablet PCs running Windows 7 (though I would like my program to work with little modification on XP with a SMART interactive whiteboard, and for mouse users on Linux/Mac). I've written a program which hooks into the normal Windows mouse events, WM_MOUSEMOVE etc., and writes on a canvas.</p>
  
  <p>The problem is that the mouse messages are being fiddled with before they reach my application. I found that if I make long strokes and pause between strokes then the mouse messages are sent properly. But if I make several rapid short strokes, then something is doing unhelpful pre-processing. Specifically, if I make a down-stroke about 10 pixels long, and then make another downstroke about five pixels to the right of the first, then the second WM_MOUSEDOWN reports that it comes from exactly the same place as the first.</p>
  
  <p>This looks like some sort of pre-processing, perhaps so that naive applications don't get confused about double-clicks. But for my application, where I want very faithful response to rapid gestures, it's unhelpful.</p>
  
  <p>I found a reference to the MicrosoftTabletPenServiceProperty atom, and to CS_DBLCLKS window style, and I turned them both off with the following piece of Python code:</p>
  
  <pre><code>hwnd = self.GetHandle()  
  tablet_atom = "MicrosoftTabletPenServiceProperty" 
  atom_ID = windll.kernel32.GlobalAddAtomA(tablet_atom)  
  windll.user32.SetPropA(hwnd,tablet_atom,1)  
  currentstyle = windll.user32.GetClassLongA(hwnd, win32con.GCL_STYLE)  
  windll.user32.SetClassLongA(hwnd, win32con.GCL_STYLE, currentstyle &amp; ~win32con.CS_DBLCLKS) 
  </code></pre>
  
  <p>But it has no effect.</p>
  
  <p>I tried writing a low-level hook for the mouse driver, with SetWindowsHookEx, but it doesn't work -- obviously the mouse messages are being pre-processed even before they are sent to my low-level Windows hook.</p>
  
  <p>I would be very grateful for advice about how to turn off this pre-processing. I do not want to switch to RealTimeStylus -- first because it won't work on Windows XP plus SMART interactive whiteboard, second because I can't see how to use RealTimeStylus in CPython, so I would need to switch to IronPython, and then my code would no longer run on Linux/Mac.</p>
  
  <p>Damon.</p>