Block/Nullify mouse movement/click in C#

2019-01-29 08:10发布

问题:

I am writing an application to fully control the mouse click/movement.

For instance, if I have the application running, form fully transparent, fullscreen, then if I click the mouse button, in normal case, it will bring the application in background in focus - I need to stop this from happening (i.e. clicking the button and nothing visible should happen on the screen), as I need to process all the mouse activity and send it out using this application.

I need to allow 2 mouse to act independently, and I am using this as an overlay, creating 2 fake pointers by drawing using C#, whist disabling the real mouse.

回答1:

What you are referring to is called mouse capture - and it can be done it both Windows Forms as well as WPF and WinAPI directly.

Here's the way to do it in WinForms.

At the WinAPI level you can use the SetCapture( HWND w ) function call.



标签: c# click mouse