Page 1 of 1

Send left double click to external application

Posted: Wed Feb 12, 2020 6:41 am
by jacky
Hi,

this sounds incredible easy but it can't get it to work :oops:

Code: Select all

          Protected.i hWnd
          Protected pt.POINT
          GetCursorPos_(@pt)
          hWnd = WindowFromPoint_(PeekQ(@pt))
          Debug SendMessage_(hWnd, #WM_LBUTTONDBLCLK, #MK_LBUTTON, pt\x + pt\y << 16)
Debug returns zero so the target application (which has focus) should have processed the event.
But it seems it only executes a single click (it's a file manager and I'm trying to send the double click when e.g. hovering over a folder to enter) because it just goes into rename mode instead of entering the folder.

Am I doing it wrong?

Re: Send left double click to external application

Posted: Wed Feb 12, 2020 7:19 am
by Michael Vogel
Workaround (not tested)...

Code: Select all

Procedure MouseClick()

	mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
	mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)

EndProcedure

Procedure DoubleClick(handle,x,y)

	Protected Cursor.Point
	Protected dot.Point
		
	GetCursorPos_(Cursor)
	if handle
		ClientToScreen_(handle,dot)
		SetCursorPos_(dot\x+10,dot\y+10)
	else
		SetCursorPos_(x,y)
	endif

	MouseClick()
	MouseClick()
	SetCursorPos_(Cursor\x,Cursor\y)

EndProcedure


Re: Send left double click to external application

Posted: Wed Feb 12, 2020 8:39 am
by BarryG
jacky wrote:it seems it only executes a single click
So send it twice. :)

Re: Send left double click to external application

Posted: Wed Feb 12, 2020 8:45 am
by jacky
Thank you, Michael!

Unfortunately this doesn't work in my case. I use a low-level mouse hook and I capture a double click event in there and I don't want to pass the message back to the system queue (I use a ProcedureReturn #True instead of calling the hook again). When I use a SetCursorPos and mouse_event_ way it brings my app to a non-responding state and hangs it so hard that I can't get rid of that process without rebooting the PC.

SendMessage_ doesn't create this problem so I guess I need to find a way to do what it should :(

@BarryG
It doesn't work that way. At least not here. Even when doing it two times in a row I don't get a double click. Don't know why...

Re: Send left double click to external application

Posted: Wed Feb 12, 2020 8:58 am
by BarryG
This may be why it doesn't work -> https://stackoverflow.com/questions/548 ... cs-dblclks

It seems windows must opt-in to receive double-click messages by setting the #CS_DBLCLKS style.

You could send #WM_LBUTTONDOWN and #WM_LBUTTONUP messages twice in a row instead. That's how my app does it.

Also, are you 100% sure the right hWnd is being used? I tried your example with my mouse over Notepad, and the hWnd wasn't Notepad's (WindowFromPoint wasn't getting Notepad), so the clicking failed.

Re: Send left double click to external application

Posted: Wed Feb 12, 2020 11:25 am
by jacky
It's the right window, I guess. Different parts of the app have different hWnds but I also tested it with the ancestor hWnd (which in this case is the hWnd of the main window).

No clue why it doesn't work. Even trying to send it directly after the hook got the single left click event doesn't lead to a double click event for e.g. entering a folder or executing the .exe where the mouse is over...

I thought maybe pt\x + pt\y << 16 is wrong and I've used pt\x + (pt\y << 16) as well but still no joy.

Re: Send left double click to external application

Posted: Wed Feb 12, 2020 3:02 pm
by RASHAD
It is so difficult to answer with approximately no information
Shoot in the dark
Try

Code: Select all

SendMessage_(#HWND_BROADCAST, #WM_LBUTTONDBLCLK, #MK_LBUTTON, 0)

Re: Send left double click to external application

Posted: Wed Feb 12, 2020 10:34 pm
by BarryG
Related thread -> viewtopic.php?f=13&t=72378

jacky, does the window being clicked need to be in the foreground/active?

Re: Send left double click to external application

Posted: Tue Feb 18, 2020 12:13 am
by jacky
Sorry for the late reply!

I didn't get it to work even with the broadcast event.
I have too much on the plate currently and was working on other parts of the app.

If I have a little bit more time I'll try it again ;)

@BarryG:
I'm checking if the destination window is under the mouse cursor already and with the click it will become the active and foreground app

Regards,
jacky

Re: Send left double click to external application

Posted: Tue Feb 18, 2020 2:45 am
by chi

Code: Select all

GetCursorPos_(pt.POINT)
Delay(2000) 
Debug Hex(GetAncestor_(WindowFromPoint_(PeekQ(pt)), #GA_ROOT))