Press a button in a window popup

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Press a button in a window popup

Post by kashmirLZ » 07 Oct 2022, 01:00

A window will popup.
The title will always be the same.
The size will always be the same.

There will be 2 buttons. I need to press one of them when it pops up.

Ladies and gentlemen, how do I begin? :?:

Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Press a button in a window popup

Post by Rohwedder » 07 Oct 2022, 02:44

Hallo,
use WinSpy and then something like this:

Code: Select all

#Persistent
SetTimer, Timer, 500
Timer:
IF WinActive("WinTitle")
	ControlClick, Control-or-Pos, WinTitle
Return

kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Re: Press a button in a window popup

Post by kashmirLZ » 07 Oct 2022, 05:42

Rohwedder wrote:
07 Oct 2022, 02:44
Hallo,
use WinSpy and then something like this: ...
Thanks @Rohwedder for the quick response.
Is this WinSpy?
Image

Does WinActive work if the pop-up goes to the background?

Is your code written in AHK v1 or v2?

For ControlClick, once I have my XY coordinates, would I simply modify your line like this?

Code: Select all

ControlClick, Control-or-Pos, WinTitle
ControlClick, x55 y77, Some Window Title
Do I need quotes in that Window Title if there are spaces?

Are partial window titles matched?

kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Re: Press a button in a window popup

Post by kashmirLZ » 07 Oct 2022, 11:58

Unfortunately the program's main window and its pop-up will have the same window title.
I need to click the pop-up.

How to unique differentiate them?

Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Press a button in a window popup

Post by Rohwedder » 07 Oct 2022, 12:19

Is this WinSpy?
… Yes
Does WinActive work if the pop-up goes to the background?
No, but WinExist() can do that. However, some windows do not react in background, they want to be activated first.
Is your code written in AHK v1 or v2?
v1 (the v2 Timers are more cumbersome!)
For ControlClick, once I have my XY coordinates, would I simply modify your line like this?
… Yes
Do I need quotes in that Window Title if there are spaces?
No, it would not work with quotes (except as an expression).
Are partial window titles matched?
No but you could use:

Code: Select all

SetTitleMatchMode, 2

kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Re: Press a button in a window popup

Post by kashmirLZ » 07 Oct 2022, 23:13

Rohwedder wrote:
07 Oct 2022, 12:19
Is this WinSpy?
… Yes
Does WinActive work if the pop-up goes to the background?
No, but WinExist() can do that. However, some windows do not react in background, they want to be activated first.
Is your code written in AHK v1 or v2?
v1 (the v2 Timers are more cumbersome!)
For ControlClick, once I have my XY coordinates, would I simply modify your line like this?
… Yes
Do I need quotes in that Window Title if there are spaces?
No, it would not work with quotes (except as an expression).
Are partial window titles matched?
No but you could use:

Code: Select all

SetTitleMatchMode, 2
So what do I do if it's still not working...

Image

How do I:
detect if this window pops up
make it active (if not)
click at these coordinates (but which coordinates do I use)

I'm not even sure if I'm getting into your IF statement you posted, so how do I debug it? since we don't have print messages.

GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Press a button in a window popup

Post by GEV » 08 Oct 2022, 01:38

Do the program's main window and its pop-up have the same title and ahk_class?

If so, do you see any message box if you run this code and the pop-up appears?

Code: Select all

#Persistent
SetTimer, GetNumberOfwindowsTitle, 200 
Return 

GetNumberOfwindowsTitle: 
	; Replace "Title" by the title of the window
	WinGet, numberOfwindows, count, Title
	If (count > 1)	
		MsgBox, Number of windows: %count%
Return

Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Press a button in a window popup

Post by Rohwedder » 08 Oct 2022, 01:39

Unfortunately, WinSpys "Follow Mouse" was not enabled in the upper right corner.
Also, the Autohotkey search for HwndWrapper says that it is a very recalcitrant window class!
search.php?keywords=HwndWrapper
Maybe you will find something usable there.

kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Re: Press a button in a window popup

Post by kashmirLZ » 08 Oct 2022, 02:37

GEV wrote:
08 Oct 2022, 01:38
Do the program's main window and its pop-up have the same title and ahk_class?

If so, do you see any message box if you run this code and the pop-up appears?

Code: Select all

#Persistent
SetTimer, GetNumberOfwindowsTitle, 200 
Return 

GetNumberOfwindowsTitle: 
	; Replace "Title" by the title of the window
	WinGet, numberOfwindows, count, Title
	If (count > 1)	
		MsgBox, Number of windows: %count%
Return
No messages.
Playing further with this reveals that, even if I type the exact window title, it's not being detected at all, WinGet doesn't seem to be able to get it.

kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Re: Press a button in a window popup

Post by kashmirLZ » 08 Oct 2022, 02:54

Rohwedder wrote:
08 Oct 2022, 01:39
Unfortunately, WinSpys "Follow Mouse" was not enabled in the upper right corner.
Also, the Autohotkey search for HwndWrapper says that it is a very recalcitrant window class!
search.php?keywords=HwndWrapper
Maybe you will find something usable there.
Image

kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Re: Press a button in a window popup

Post by kashmirLZ » 08 Oct 2022, 22:18

Help me out :)

GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Press a button in a window popup

Post by GEV » 09 Oct 2022, 01:04

Sorry,
the right syntax is

Code: Select all

#Persistent
SetTimer, GetNumberOfwindowsTitle, 200 
Return 

GetNumberOfwindowsTitle: 
	; Replace "Title" by the title of the window
	WinGet, numberOfwindows, count, Title
	If (numberOfwindows > 1)	
		MsgBox, Number of windows: %numberOfwindows%
Return

kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Re: Press a button in a window popup

Post by kashmirLZ » 10 Oct 2022, 03:43

Alright where am I going wrong here?
This sends a click, but not at the coordinates that I need.
If I put my cursor above the button I need it to click, then it clicks that button, otherwise not.
I've tried Click and ControlClick.
What am I missing?

Code: Select all

#Persistent

; SetTitleMatchMode, 2
SetControlDelay 1

SetTimer, checkWindow, 1000

checkWindow(){ 
	if WinExist("title"){
        WinGetPos, , , W, H
        ;MsgBox, Window size is %W%x%H%
        if (W = 1251 and H = 747) {
            ;MsgBox, Calling WinActivate and trying to click
            WinActivate
            ;ControlClick, x215 y169
            ;Click, x215 y169
            Return
        }
    }
}

Return

kashmirLZ
Posts: 41
Joined: 06 Oct 2022, 23:27

Re: Press a button in a window popup

Post by kashmirLZ » 10 Oct 2022, 04:41

I ended up having to do click in this lengthy way:

Code: Select all

#Persistent
; SetTitleMatchMode, 2
SetControlDelay 1

SetTimer, checkWindow, 5000

checkWindow(){ 
	if WinExist("title"){
        WinGetPos, , , W, H
        if (W = 1251 and H = 747) {
            WinActivate
            Sleep, 333
            Click, 34, 697 Left, , Down
            Sleep, 10
            Click, 34, 697 Left, , Up
            Sleep, 10
            Return
        }
    }
}

Return

Post Reply

Return to “Ask for Help (v1)”