0
votes

I have a script, which is working more or less.

I started a program and pressed some keys.

Depending on several factors the program show one of two screens. If the screen is number 1 then it should only run to the end (title: 10-2013 2013.06.17. Screen x). If the screen is number 2 then it should press another key and then run to the end (title: 10-2013 2013.06.17. Screen y).

The screen titles are not simple titles but they depend on some input, so here is what I tried:

SetTitleMatchMode 2
; Wait for any of the two screens
WinWait,%5%-%1% - %2% - Screen

; If it is the second screen
MyTitle = %5%-%1% - %2% - Screen y

WinGetActiveTitle,title
If(title = MyTitle)
{
    ControlSend,Static39,{Esc},%5%-%1% - %2% - Screen y
    Sleep 2000
}

; Here are the common part again    
ExitProgram:

The condition does not work. If I try it like above it does not go inside the condition. If I use %title% then it says "invalid characters in variable name 10-2013 2013.06.17. Screen y".

Solution

Based on Robert's answer

SetTitleMatchMode 2
WinWait,%5%-%1% - %2% - Screen

IfWinExist %5%-%1% - %2% - Screen y
{
    ControlSend,Static39,{Esc},%5%-%1% - %2% - Screen y
    Sleep 2000
}
1
To your syntactical problem: To check string equality, either use IfEqual, var, value or if(var = %value%). Consequentially, when comparing two string variables, one always has to be inside percent signs.MCL
I tried if(var = %value%) but gave me a similair error.Biri

1 Answers

0
votes

To check for multiple windows, use ahk_group like this:

GroupAdd, GroupName, ahk_class AutoHotKey
GroupAdd, GroupName, ahk_class CalcFrame

WinWait, ahk_group GroupName

Then check for each window individually

IfWinExists, ahk_class AutoHotKey
{
 WinActivate
 Do your thing
}
Else IfWinExists, ahk_class CalcFrame
{
 WinActivate
 Do your thing
}
Return

You can do this with SetTitleMatchMode, 2 and parts of the title as well