Send left double click to external application

Windows specific forum
jacky
User
User
Posts: 66
Joined: Mon Jan 21, 2019 1:41 pm

Send left double click to external application

Post 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?
User avatar
Michael Vogel
Addict
Addict
Posts: 2807
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Send left double click to external application

Post 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

BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Send left double click to external application

Post by BarryG »

jacky wrote:it seems it only executes a single click
So send it twice. :)
jacky
User
User
Posts: 66
Joined: Mon Jan 21, 2019 1:41 pm

Re: Send left double click to external application

Post 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...
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Send left double click to external application

Post 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.
jacky
User
User
Posts: 66
Joined: Mon Jan 21, 2019 1:41 pm

Re: Send left double click to external application

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Send left double click to external application

Post 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)
Egypt my love
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Send left double click to external application

Post by BarryG »

Related thread -> viewtopic.php?f=13&t=72378

jacky, does the window being clicked need to be in the foreground/active?
jacky
User
User
Posts: 66
Joined: Mon Jan 21, 2019 1:41 pm

Re: Send left double click to external application

Post 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
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Send left double click to external application

Post by chi »

Code: Select all

GetCursorPos_(pt.POINT)
Delay(2000) 
Debug Hex(GetAncestor_(WindowFromPoint_(PeekQ(pt)), #GA_ROOT))
Et cetera is my worst enemy
Post Reply