Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent raw mouse clicks outside an application using c#

Tags:

c#

mouse

I am attempting to control two "mice". The primary mouse (mice) are used for controlling the cursor for normal UI control (which I don't want to intercept) and a secondary "mouse" which should only be used as input into the application I am writing and ignored otherwise.

I am successfully capturing the mouse messages and filtering as desired. I can also successfully capture the mouse inputs,even when my app is not in focus (as desired).

The only remaining issue is that I can't seem to keep the mouse from interacting with other applications. So I can essentially spy on the mouse, but not fully consume the message.

I "believe" I am preventing the "base.WndProc(ref message)" from getting called when I am processing the filtered mouse messages, but the system still seems to be getting the mouse clicks.

Is C# (Visual Studio Express 2010) able to do this?

Thank you for any assistance you might be able to give.

like image 861
ChronoFish Avatar asked Nov 30 '12 03:11

ChronoFish


3 Answers

Raw input might be what you're looking for. Here is an MSDN discussion with a similar question which has link to a codeproject article on handling mutliple keyboards in C#.

like image 86
Bikonja Avatar answered Nov 09 '22 11:11

Bikonja


You can use global mouse hook. I don't remember where I've found it, but here is the sample

like image 1
heq Avatar answered Nov 09 '22 11:11

heq


As others have stated this is at the very least troublesome in dot net. I would highly recommend you switch over to C++ / Win32 to achieve this. I think you will save yourself a lot of headache in the long run.

like image 1
major-mann Avatar answered Nov 09 '22 12:11

major-mann