确定在.NET中单击了哪只鼠标(多个鼠标设备) [英] Determine which mouse was clicked (multiple mice devices) in .NET

查看:44
本文介绍了确定在.NET中单击了哪只鼠标(多个鼠标设备)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测何时单击我的触摸板!

I want to detect when my touchpad is clicked!

我通常使用USB鼠标,所以我什么都不用触摸板.相反,当单击触摸板时,我想使在.NET中执行操作成为可能.这样,我就可以将其用作快捷方式:轻按一下就会发生一些酷的事情.

I normally use a usb mouse, so I don't use the touchpad for anything. Instead I'd like to make it possible to perform an action in .NET, when the touchpad is clicked. This way I can use it as a shortcut: One tap and something cool happens.

这是可能的,如果是,那么任何线索如何?我希望它可以在VB.NET或C#中使用.

Is this possible, and if yes, any clue how? I'd prefer if it could be working in VB.NET or C#.

我的理论是我必须做一个鼠标钩,然后才能以某种方式确定点击来自哪个设备.如果确定单击来自触摸板,则取消单击并执行doWhatever().

My theory is that I'd have to make a mousehook, which then somehow determines which device the click is coming from. If the click is determined to be from the touchpad, then cancel the click and doWhatever().

谢谢!

*编辑* 好吧,它已经解决"了:)奇怪的是,Synaptics几天前为触摸板发布了他们的最新驱动程序和软件,并提供了一些新功能.由于我的笔记本电脑带有突触触摸板,因此我试用了该软件,并且很有趣的是,它内置了用于在触控板上指定点击以执行动作的功能.

* EDIT * Well, it's "solved", sort of :) In a odd coincidence, Synaptics released their latest driver and software for their touchpads a few days ago with some new functionality. As my laptop has a synaptics touchpad, I tried out the software and interestingly enough, the functionality for designating clicks on the trackpad to perform an action, was built-in.

因此,无需一行代码(反正是我自己的代码),就可以实现所需的功能.

So the desired function has been achieved, without a line of code (my own code anyway :).

不过,请转至Adrian,获取指向RawInputSharp库的链接.我昨天对此进行了修改,并且我90%确信,如果笔记本电脑没有突触触控板,则可以将其用于此目的.

Answer goes to Adrian though for the link to the RawInputSharp library. I tinkered with it yesterday, and I'm 90% sure it would be possible to use for this purpose, in the event a laptop doesn't have a synaptics trackpad.

推荐答案

Have a look at the RawInputSharp library from this page. It uses pInvokes into User32.dll to get hold of input device information. Using it you can detect which device (ie. mouse) input is coming from.

玩了一点儿,我设法提取了一些仅显示设备ID的代码-一个不同的值,具体取决于我使用USB鼠标还是内部触摸板.棘手的事情是自动识别哪个设备ID是触摸板的ID,但是您可以在应用程序中手动配置它.

Having had a little play with it, I managed to extract some code that displays just the device id - a different value depending on whether I use my USB mouse or my internal touchpad. The tricky thing would be to identify which device id is that of your touchpad automatically, but you could manually configure this in your application.

这篇关于确定在.NET中单击了哪只鼠标(多个鼠标设备)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆