Page 1 of 1

OnMessage - Receive WM_LBUTTONDOWN event?

Posted: 06 Oct 2016, 11:59
by Guest078
Hi,

I use:

Code: Select all

OnMessage(C["MSG"]["WM_LBUTTONDOWN"], "WM_MOUSECLICKS")
in the autoexecute part of my script (the associative array contains the hex value for WM_LBUTTONDOWN) and the WM_MOUSECLICKS function outputs wParam, lParam, msg and the hwnd.

It works fine if I click anywhere inside any of my own gui window(s) but I'd like to capture this left mouse down event if the mouse is used in a different application (e.g. Windows File Explorer).

Is that possible with AHK?

Re: OnMessage - Receive WM_LBUTTONDOWN event?

Posted: 06 Oct 2016, 12:27
by guest3456
Guest078 wrote: It works fine if I click anywhere inside any of my own gui window(s) but I'd like to capture this left mouse down event if the mouse is used in a different application (e.g. Windows File Explorer).

Is that possible with AHK?
its possible but i believe you'd need to inject a dll into all processes. meaning, its not trivial. ahk's OnMessage will only monitor messages of its own process.

you could hack your way around this by implementing an ~LButton down hotkey, and checking the coordinates and window of the click with MouseGetPos

Re: OnMessage - Receive WM_LBUTTONDOWN event?

Posted: 06 Oct 2016, 16:54
by lexikos
I wouldn't call that a hack; more like the most efficient solution. LButton hotkeys fire when AutoHotkey's mouse hook receives a WM_LBUTTONDOWN message.

Even if you want to use a hook, you don't need a dll. AutoHotkey does it without a dll. You just need to use the right hook.

Re: OnMessage - Receive WM_LBUTTONDOWN event?

Posted: 06 Oct 2016, 17:31
by drawback
Ok, thanks!

@lexikos:
Any hints how to implement this? I only need to listen for this event for a specific application (for example: Windows File Explorer)

Re: OnMessage - Receive WM_LBUTTONDOWN event?

Posted: 06 Oct 2016, 21:47
by lexikos
???
implementing an ~LButton down hotkey

Code: Select all

~LButton::
   MsgBox You clicked?
   return
If you want to restrict it to specific applications, use the MouseIsOver example.

Re: OnMessage - Receive WM_LBUTTONDOWN event?

Posted: 07 Oct 2016, 13:45
by drawback
Sorry, you're right lexikos. I though about a specialized hook but a hotkey is sufficient in this case. Me culpa!