How do I check if the user clicked with a mouse or with a pen stylus on a C# control.
如何检查用户是否在C#控件上用鼠标或笔式触控笔单击。
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
编辑:使用Windows窗体而不是WPF
3 个解决方案
#1
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:
我为MSDN撰写了一篇从未发表过的文章,我想是因为平板电脑的开发在我得到它们的时候就失败了。但它描述了如何做到这一点。简而言之,您需要GetMessageExtraInfo API。这是定义:
// [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.
如果您希望我将文章发给您,请在爱因斯坦科技网点以我的名字给我发电子邮件。
#2
If you're using WPF then there's a whole host of Stylus events. E.g. UIElement.StylusDown.
如果您正在使用WPF,那么就会有大量的Stylus事件。例如。 UIElement.StylusDown。
This has more details about how stylus and mouse events interact.
这有关于手写笔和鼠标事件如何交互的更多细节。
If you're not using WPF, why not? :p
如果您不使用WPF,为什么不呢? :p
#3
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.
我真的不太了解这个,但我想如果有人使用手写笔,那么mouseEnter,mouseExit(或任何相应的东西)事件将永远不会触发。如果有人被解雇,那么你知道他们正在使用鼠标。
#1
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:
我为MSDN撰写了一篇从未发表过的文章,我想是因为平板电脑的开发在我得到它们的时候就失败了。但它描述了如何做到这一点。简而言之,您需要GetMessageExtraInfo API。这是定义:
// [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.
如果您希望我将文章发给您,请在爱因斯坦科技网点以我的名字给我发电子邮件。
#2
If you're using WPF then there's a whole host of Stylus events. E.g. UIElement.StylusDown.
如果您正在使用WPF,那么就会有大量的Stylus事件。例如。 UIElement.StylusDown。
This has more details about how stylus and mouse events interact.
这有关于手写笔和鼠标事件如何交互的更多细节。
If you're not using WPF, why not? :p
如果您不使用WPF,为什么不呢? :p
#3
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.
我真的不太了解这个,但我想如果有人使用手写笔,那么mouseEnter,mouseExit(或任何相应的东西)事件将永远不会触发。如果有人被解雇,那么你知道他们正在使用鼠标。