5

How do I check if the user clicked with a mouse or with a pen stylus on a C# control.

For eg. If the user clicks a text box with a pen button then I want an input panel to pop up but if he clicks with a mouse then it shouldn't. So how do I check whether he was using a mouse or a pen?

Edit: Using Windows Forms not WPF

Ksempac
  • 1,842
  • 2
  • 18
  • 23
Anirudh Saraf
  • 179
  • 1
  • 11

3 Answers3

6

I wrote an article for MSDN that never got published, I guess because Tablet PC development fizzled out by the time I got it to them. But it described how to do this. Long story short, you'll want the GetMessageExtraInfo API. Here's the definitions:

// [DllImport( "user32.dll" )]
// private static extern uint GetMessageExtraInfo( );

uint extra = GetMessageExtraInfo();
bool isPen = ( ( extra &  0xFFFFFF00 ) == 0xFF515700 );

Email me at my first name at Einstein Tech dot net if you want me to send you the article.

Josh
  • 68,005
  • 14
  • 144
  • 156
  • found a link to a MSDN article which explains why the above works, along with other info. http://msdn.microsoft.com/en-us/library/ms703320.aspx – Anirudh Saraf Apr 20 '09 at 00:40
0

If you're using WPF then there's a whole host of Stylus events. E.g. UIElement.StylusDown.

This has more details about how stylus and mouse events interact.

If you're not using WPF, why not? :p

Ray
  • 45,695
  • 27
  • 126
  • 169
-1

I don't really know too much about this, but I'd guess that if someone is using a stylus, then the mouseEnter, mouseExit (or whatever the equivalent is) events won't ever fire. If one does get fired, then you know that they're using a mouse.

nickf
  • 537,072
  • 198
  • 649
  • 721