BtnClick() - Click button without activating target window

Post your working scripts, libraries and tools for AHK v1.1 and older
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

BtnClick() - Click button without activating target window

25 Sep 2016, 03:57

Similar to ControlClick, but without activating the target window.

Code: Select all

BtnClick(Control, WinTitle:="", WinText:="", ExcludeTitle:="", ExcludeText:="") {
	static WM_COMMAND := 0x111, BN_CLICKED := 0

	if WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText) {
		ControlGet, hwndCtl, Hwnd,, %Control%
		CtrlID := DllCall("GetDlgCtrlID", "ptr", hwndCtl)
		SendMessage, WM_COMMAND, (BN_CLICKED << 16) | (CtrlID & 0xffff), hwndCtl
	}
}
Last edited by tmplinshi on 28 Sep 2016, 04:02, edited 3 times in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: BtnClick() - Click button without activating target window

25 Sep 2016, 04:45

What is the difference when specifying the NA option for Controlclick? I'm going to try this, I have had some troubles with some specific windows and controlclick so I'm always on the look out for alternatives. Thanks for sharing.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: BtnClick() - Click button without activating target window

25 Sep 2016, 05:16

Helgef wrote:What is the difference when specifying the NA option for Controlclick?
ControlClick sends a completely different windows message (WM_LBUTTONDOWN/UP) and therefore ControlClick also allows you to specify x/y coordinates instead of requiring a controlname

i have no idea what WM_COMMAND/BN_CLICKED does
Helgef wrote: I'm going to try this, I have had some troubles with some specific windows and controlclick so I'm always on the look out for alternatives. Thanks for sharing.
see here:
https://autohotkey.com/board/topic/9695 ... k-improve/
Last edited by guest3456 on 25 Sep 2016, 05:22, edited 1 time in total.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: BtnClick() - Click button without activating target window

25 Sep 2016, 05:17

I see, thanks.

Edit: Thanks for the links.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: BtnClick() - Click button without activating target window

25 Sep 2016, 06:15

Helgef wrote:What is the difference when specifying the NA option for Controlclick? I'm going to try this, I have had some troubles with some specific windows and controlclick so I'm always on the look out for alternatives. Thanks for sharing.
Damn, I've used the NA many times for "improve reliability" reason, but I had never read carefully on documentation of this NA option and its meaning, I did know NA option in Gui, Show command... :oops:
Thank you, now I know clearly.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: BtnClick() - Click button without activating target window

25 Sep 2016, 07:17

tmplinshi wrote:did know NA option in Gui, Show command... :oops:
I was just thinking about where else I had encountered the NA option, thanks! :)

Btw, I tested your function and it works fine (win7 ahk 1.1.22.09 U64), and since this doesn't do mouse clicks, as pointed out by guest3456, it could be very useful in case some control ignores the mouse click messages. Also, it is more discreete, it doesn't highlight or animate a push on the button. It's a keeper!
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: BtnClick() - Click button without activating target window

06 Mar 2017, 16:29

Helgef wrote:it could be very useful in case some control ignores the mouse click messages.
Indeed :wave:
omareg94
Posts: 94
Joined: 27 Jun 2016, 22:46

Re: BtnClick() - Click button without activating target window

25 Mar 2017, 21:45

I've tried these:

Code: Select all

; Example A (Not working):
BtnClick("Get Time", "Current Time (with Milliseconds)BBB ahk_class QWidget ahk_exe vlc.exe")
; Example B (Not working):
BtnClick("Button1", "Current Time (with Milliseconds)BBB ahk_class QWidget ahk_exe vlc.exe")
Both are not working. I'm trying to push down (click) a dialog button within a background window without using Keyboard/Mouse key click simulation (My Question). I think they aren't working because the ClassNN of the button seems wrong as I'm not able to capture it via Window Spy or AccViewer.

Could you please help how could I make BtnClick work?

Thanks in advance.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 179 guests