开发者

C# - track WM_LBUTTONDOWN outside the form

I want to get when the left mouse is clicked, outside of the form. I've found this can be done with WM_LBUTTOND开发者_运维问答OWN, but I have been searching for hours and yet haven't found out how to get it to work...

Thanks in advance


Yes, indeed, you need a global hook. The resource that Blorgbeard posted does indeed work, with a few modifications.
When the calls to 'SetWindowsHookEx' are made in HookManager.Callbacks.cs change the argument:

Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0])
// to this:
IntPtr.Zero

And it will suddenly start working. Come to think of it, I also changed the target platform from 2.0 to 4.0 as well. You might need to do that too. Anyway, works like a charm.


Global hook is somehow overheaded, you could call SetCapture to capture the mouse event.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜