When developing for a tablet PC, how do I determine if the user clicked a mouse or a pen?

安稳与你 提交于 2019-11-30 14:49:46

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!