Why does WM_LButtonDown fire twice?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jly
Posts: 89
Joined: 30 Sep 2020, 06:06

Why does WM_LButtonDown fire twice?

22 Feb 2022, 20:40

Why does WM_LButtonDown fire twice when the child window is clicked?

Is there any way to make WM_LButtonDown fire only once?
Or how to judge whether the main window or the child window is triggered?

Execute the following code, you can observe that when the child window is clicked once,
WM_LButtonDown will be triggered twice.

Code: Select all

gui,p:+OwnDialogs +hwndhm
gui,p:Color,White
gui,p:show,w800 h500

gui,child1:+Parentp +hwndhm1
gui,child1:color,00BFFF
gui,child1:show,x200 y100 w500 h300

gui,child2:+Parentp  +hwndhm2
gui,child2:color,FF6347
gui,child2:show,x70 y150 w400 h200

OnMessage(0x201, "WM_LButtonDown")
Return

WM_LButtonDown(wparam, lparam, msg, hwnd )
{
	global
	ToolTip % A_Tickcount "`n" hwnd " = " ToBase(hwnd,16) " = " hm " = " hm1 " = " hm2 "`n"  wparam  " = " lparam  " = " msg
	sleep,1000
}
ToBase(n,b){
	return (n < b ? "" : ToBase(n//b,b)) . ((d:=Mod(n,b)) < 10 ? d : Chr(d+55))
}
esc::ExitApp
Attachments
20220223_093936.png
20220223_093936.png (31.72 KiB) Viewed 446 times
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Why does WM_LButtonDown fire twice?

23 Feb 2022, 09:42

It seems that when you click on a child window it registers two clicks. I'm guessing the click on the child is being passed to the parent as well. I'm not sure how to prevent this maybe others can help.

If you want a quick hacky fix you can filter out the second click like this. Note I am using fileappend with * to write to the console. If you don't have an editor with one you can put back in your tooltip. I noticed the the two A_Tickcount values in the registered clicks were identical but if you start to add a lot of code here you may need to do a check if the second message was within a certain small timeframe instead

Code: Select all

gui,p:+OwnDialogs +hwndhm
gui,p:Color,White
gui,p:show,w800 h500

gui,child1:+Parentp +hwndhm1
gui,child1:color,00BFFF
gui,child1:show,x200 y100 w500 h300

gui,child2:+Parentp  +hwndhm2
gui,child2:color,FF6347
gui,child2:show,x70 y150 w400 h200

OnMessage(0x201, "WM_LButtonDown")
Return

WM_LButtonDown(wparam, lparam, msg, hwnd )
{
	static last_tickcount
	
	if (A_Tickcount = last_tickcount)
		return
	
	FileAppend, % "Tickcount: " A_Tickcount " wParam: " wparam " lParam: " lparam " msg: " msg " hwnd: " hwnd "`n", *
	
	last_tickcount := a_tickcount
}

ToBase(n,b){
	return (n < b ? "" : ToBase(n//b,b)) . ((d:=Mod(n,b)) < 10 ? d : Chr(d+55))
}
esc::ExitApp


User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: Why does WM_LButtonDown fire twice?

23 Feb 2022, 10:38

Try using 0x202 (button up). See what happens.
14.3 & 1.3.7

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Kodakku and 368 guests