Windows: Tablets not detected correctly

I use a Wacom graphics tablet instead of a mouse for everything (multimedia power user). Occasionally I stumble across a commercial plugin that is uncontrollable due to incorrect tablet detection. I just tried iPlug2 for the first time (looks great) and found the same issue (I bet those plugins were using iPlug2 :slight_smile:)

The problem is the widely quoted detection code, which seems to be incomplete. This version works correctly with both my tablet and a mouse on Win10 Pro (x64):

void IGraphicsWin::CheckTabletInput(UINT msg)
{
  if ((msg == WM_LBUTTONDOWN) || (msg == WM_RBUTTONDOWN) || (msg == WM_MBUTTONDOWN) || (msg == WM_MOUSEMOVE)
      || (msg == WM_RBUTTONDBLCLK) || (msg == WM_LBUTTONDBLCLK) || (msg == WM_MBUTTONDBLCLK)
      || (msg == WM_RBUTTONUP) || (msg == WM_LBUTTONUP) || (msg == WM_MBUTTONUP)
      || (msg == WM_MOUSEHOVER) || (msg == WM_MOUSELEAVE))
  {
    const LONG_PTR c_SIGNATURE_MASK = 0xFFFFFF00;
    const LONG_PTR c_MOUSEEVENTF_FROMTOUCH = 0xFF515700;
    
    LONG_PTR extraInfo = GetMessageExtraInfo();
    bool touch_or_tablet = !(((extraInfo & 0x7F) && (IsWindowsVistaOrGreater()? (extraInfo & 0x80) : 1)) || ((extraInfo & c_SIGNATURE_MASK) == c_MOUSEEVENTF_FROMTOUCH));
    SetTabletInput(touch_or_tablet);

    mCursorLock &= !mTabletInput;
  }
}

credit: http://hg.libsdl.org/SDL/rev/8254c364ec4a

thanks for this, i am also a wacom tablet user, although not normally on windows. i’ll check it out

1 Like

Great. Very excited about IPlug2 after having spent (on an off) years on coding for SynthEdit, which is unfortunately a deeply flawed platform, at least the old version I’m still on (1.1). I can see just how much work has gone into iPlug2 so very appreciative it exists & just about to start porting code.

BTW, I did buy your Endless plugin some time ago and used it on a favourite song :). I didn’t realise you were also the iPlug2 author (had never really looked at it).

Thanks - are you able to make a PR on GitHub for this? I wrote the original version for my fork of iPlug 1 and it was pre windows 10 - the code did work for my Wacom tablet, but perhaps this is more robust. If you had some kind of reference for the way you are testing that would also be handy as we may not be able to directly test all relevant systems.

In terms of the code you’ve used snake case for touch_or_tablet, which is not iPlug2 style (sorry to be pedantic) - if you corrected that to TouchOrTablet then it’s likely we’d be able to merge directly.

I’ll look at GitHub shortly. Coding style no prob, it’s important to me for my own code too (I use quite intense formatting).

Below my 1st post is the link to where I found these tests (libSDL). My (unconfirmed) hunch was that the existing code only checks for touch input, while Wacom’s (and maybe others) graphics tablet pen synthesized mouse events are recognized differently. Can’t confirm that yet, but it does work correctly here.

EDIT: Lol, looking closer at their code, I missed the comments that spell it out:

/* Mouse data (ignoring synthetic mouse events generated for touchscreens) */
/* Versions below Vista will set the low 7 bits to the Mouse ID and don't use bit 7:

   Check bits 8-32 for the signature (which will indicate a Tablet PC Pen or Touch Device).

   Only check bit 7 when Vista and up(Cleared=Pen, Set=Touch(which we need to filter out)),

   when the signature is set. The Mouse ID will be zero for an actual mouse. */

*checkTouch = (!(((extrainfo & 0x7F) && (isVistaOrNewer ? (extrainfo & 0x80) : 1)) || ((extrainfo & 0xFFFFFF00) == 0xFF515700)));

Sorry - I didn’t have my contacts in earlier (at least that’s not my excuse for seeing the link :wink: )

I imagine we’ll want to merge this in as soon as we can - PRs/issues are just useful for making sure we don’t lose track of things. The forum is best for discussion.

Appreciate your time on this!

… remember when you first had to learn Git (argh!).

I may have done this right (fork project, create appt. named branch, commit changes there, create PR): https://github.com/iPlug2/iPlug2/pull/550

(don’t ask me how long it took to get it right… I hope :wink: )

Thanks so much for persevering - all looks good!

1 Like