开发者

Determine which mouse was clicked (multiple mice devices) in .NET

开发者 https://www.devze.com 2022-12-23 20:00 出处:网络
I want to detect when my touchpad is clicked! 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 touc

I want to detect when my touchpad is clicked!

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.

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

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().

Thanks!

* EDIT * Well, it's "solved", sort of :) In a odd coin开发者_开发知识库cidence, 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 :).

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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号