Click here to Skip to main content
12,554,869 members (58,019 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I want to handle two mices' click events in C#.
Posted 14-Mar-12 8:38am
Updated 26-Aug-16 11:46am
Ed Nutting38.7K
Wes Aday 14-Mar-12 14:50pm
Why on earth would you want to do this at all?
ryanb31 14-Mar-12 14:55pm
Do you need to do something depending on which mouse it is? You do not have to code for this. Mouse clicks and moves will be registered as normal.
Ed Nutting 14-Mar-12 15:03pm
Edit: Don't SHOUT - it's annoying and rude.

Furthermore, this is a demand for code/answer not a question. A question explains the problem, says what you have tried already, shows some effort has gone into solving it and then asks a specific and clear question and lastly, has a question mark. Your post fails all of this hence it is a demand. Please update your question to fix this issue, then someone might be able to help.

Philippe Mori 14-Sep-15 13:05pm
Even though, it usually does not make much sense, it is somewhat an interesting question...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You don't. At least with the standard mouse drivers, Windows doesn't handle multiple mice, so your app can't do it either.

You can plug multiple mice into the machine, but you only have the one mouse pointer. If you move both mice, they will "fight" for control of the mouse pointer.

The only way to get multiple mouse pointers is if you use mouse drivers specifically written to handle this. For example, CPNMouse[^].
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Microsoft Mouse Mischief SDK, a free multi-mouse driver implemented as an add-in for PowerPoint, may shed some light on this topic. It appears that MS has figured out how to extract the HW device ID for each mouse and track them separately. I know several other groups (companies) have also figured out how to do this for their software apps. But I haven't developed the code myself yet. A quick glance over the MS SDK it appears that they are using the USB port related HW info, instead of the device-carried info, which may not be available anyway.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Since Windows Vista:

C++ & RawInput!

Example of Unity plugin:

C++ DLL:
C# script for Unity:

Check these. You should be able to at least understand what the C++ part is doing and how it interops with the C# script via P/Invoke.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 26 Aug 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100