WinWait will not not working correctly

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Caporeira
Posts: 14
Joined: 23 Mar 2021, 08:05

WinWait will not not working correctly

18 May 2021, 16:08

Hi, it's my first script in AHK.

I would like:
1. Open MessageBox
2. Wait 1-90 second
3. Typing some code
4. Run program
4. Wait few second for Window
5. If Windows is opened, click OK
6. If i cancel or timeout is out, i don't wont to exit this script.

Now is working not correct, if MessageBox is few second aktiv, on step 6 ist OK pressed. If MessageBox is only short time aktiv, OK button is not pressed.

Code: Select all

^q::
InputBox, code, Input code dialogue, Please enter your code, ,200, 140, , , local ; 

if ErrorLevel
    MsgBox, CANCEL was pressed.

Run C:\Program Files\Viscosity\Viscosity.exe

WinWait,  ahk_class HwndWrapper[Viscosity.exe;CwpfDetails;1321437b-4494-40a9-acd7-65d649b10046],, 90
if ErrorLevel
    {
    MsgBox, WinWait timed out.
    return
    }
else
    MsgBox, Viscosity is opened
    continue
    ControlClick, OK, Viscosity

return
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: WinWait will not not working correctly

18 May 2021, 16:12

Your Else statement suggests that you want a block to execute, but AHK requires blocks to be enclosed in braces.

Continue works only inside a loop.

If the input box is dismissed, you are proceeding with the rest of the routine anyway, instead of returning.
Caporeira
Posts: 14
Joined: 23 Mar 2021, 08:05

Re: WinWait will not not working correctly

21 May 2021, 17:26

mikeyww wrote:
18 May 2021, 16:12
Your Else statement suggests that you want a block to execute, but AHK requires blocks to be enclosed in braces.

Continue works only inside a loop.

If the input box is dismissed, you are proceeding with the rest of the routine anyway, instead of returning.
Thank you for advise.

On this video (gif file) ich have run my script twice:
https://www.dropbox.com/s/p6au21fsc7q36gs/AHK.gif?dl=0

First one is clicked OK button, but second one have not done this.
Why it is so ?
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: WinWait will not not working correctly

21 May 2021, 19:45

I cannot see anything happening in the GIF. Posting a revised script that addresses the noted bugs might help in generating additional feedback.
Caporeira
Posts: 14
Joined: 23 Mar 2021, 08:05

Re: WinWait will not not working correctly

25 May 2021, 01:51

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^q::
InputBox, code, Input code dialogue, Please enter your code, ,200, 140, , , local ; Check 6 digit
sleep, 2000
if ErrorLevel
    MsgBox, CANCEL was pressed.

Run C:\Program Files\Viscosity\Viscosity.exe connect "FBCORP CAVPN (Kunden)"

if WinExist("Viscosity")
{   
    WinActivate ; Use the window found by WinExist.
    ControlClick, OK, Viscosity
}
else  WinExist("Viscosity - CAVPN)")
{
    WinActivate ; Use the window found by WinExist.
}
SendInput {Right}
SendInput {BackSpace 6}
sleep, 1000
Send %code%
; sleep, 2000
; SendInput {Enter}
Acuelly i have to Problems.
- Sometimes if the Widows "Viscosity" script is not clicking on OK button
- SendInput {Right} {BackSpace 6} delete my whole old entry (i want to delete only 6 last old password letters)
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: WinWait will not not working correctly

25 May 2021, 06:00

I have no way to test this, but some tips are below.

1. If user cancels, you probably want to Return instead of proceeding.

2. After a Run, issue a WinWaitActive, because the program window will not immediately exist.

3. Instead of "else... [function]", use "else if [function]".

4. You might need to send {End} or ^{Right} to get to the end of your field or word.
Caporeira
Posts: 14
Joined: 23 Mar 2021, 08:05

Re: WinWait will not not working correctly

31 May 2021, 04:41

mikeyww wrote: I have no way to test this, but some tips are below.

1. If user cancels, you probably want to Return instead of proceeding.

2. After a Run, issue a WinWaitActive, because the program window will not immediately exist.

3. Instead of "else... [function]", use "else if [function]".

4. You might need to send {End} or ^{Right} to get to the end of your field or word.
Thank you very much. With your advice, it's working very well. But unfortunetlly is still problem either with WinActivate("Viscosity") or ControlClick, OK, Viscosity :(
The Windows is opening and nothing is happening.

Code: Select all

^q::
InputBox, code, Input code dialogue, Please enter your code, ,200, 140, , , local ; Check 6 digit
sleep, 2000
if ErrorLevel
{
    MsgBox, Cancel was pressed.
    return
}

Run C:\Program Files\Viscosity\Viscosity.exe connect "CAVPN)"

WinWaitActive, Viscosity,, 10

if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}

if  WinExist("Viscosity - CAVPN")
{
    WinActivate ; Use the window found by WinExist.
}

else if WinExist("Viscosity")
{   
    WinActivate ; Use the window found by WinExist.
    ControlClick, OK, Viscosity
}

SendInput {Right}
SendInput {BackSpace 6}
sleep, 1000
Send %code%
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: WinWait will not not working correctly

31 May 2021, 06:44

To debug your script, you can add code to each of the WinExist sections, so that you understand which condition is true. You can also run Window Spy to identify the control name for your button.

If neither condition is true at the moment the command is executed, then the script will simply continue to the next command. Your debugging lines will indicate whether this is the case.
Caporeira
Posts: 14
Joined: 23 Mar 2021, 08:05

Re: WinWait will not not working correctly

16 Sep 2021, 03:36

Ok Button ist selected, but not pressed.
How to fix ist ?

Code: Select all

else if WinExist("ahk_class HwndWrapper[Viscosity.exe;CwpfDetails;993c5735-d967-4fbe-a048-4e7c56bf5686]")
{   
    ; MsgBox, Windows Viscocity.
    WinActivate ;, Viscosity ; Use the window found by WinExist.
    sleep, 2000
    ControlClick, OK, Viscosity
    ; MsgBox, WinActive(WinTitle, WinText)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AHK_user and 210 guests