If statement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Gurthen
Posts: 4
Joined: 03 Mar 2018, 11:54

If statement

Post by Gurthen » 22 Jun 2021, 10:28

I have 2 scripts running, one is an ahk script and another is an image finder (other program)
They both communicate with each other and it works fine

AHK script sends a key to activate the other and wait for it to find the image which then receives a 'a' input and moves on

Code: Select all

Input, SingleKey, C, a ; Wait for other script to finish
Now I've been trying to add an if statement depending on what the other script finds. If it's X image sends 'a' if it's Y image it sends 'b'
I tried

Code: Select all

    Input, SingleKey, C, a,b ; Wait for other script to finish
    ;----- ShortCut
    If (SingleKey = a)
{
        Sleep 3000
        MouseMove 1177, 82 ;    Close
        Send {LButton}
        Sleep 5000
        Send z
        Sleep 940000
        Send z
        Sleep 19000
}
    If (SingleKey = b)
{
        MouseMove 784, 987 ; check result
        Send {LButton}
        Sleep 1500
        MouseMove 954, 683 ; Confirm
        Send {LButton}
        Sleep 3000
        MouseMove 1177, 82 ;    Close
        Send {LButton}
        Sleep 60500
}
Which will work if the 'a' is pressed but will not do anything if the 'b' is pressed.

I also tried

Code: Select all

    Input, SingleKey, C, a,b ; Wait for other script to finish
    ;----- ShortCut
    If (SingleKey = a)
{
...
}
   Else If (SingleKey = b)
{
...
}
and

Code: Select all

    Input, SingleKey, C, a,b ; Wait for other script to finish
    ;----- ShortCut
    If (SingleKey = a)
{
...
}
   Else
{
...
}
What am I doing wrong? :)

Thanks in advance
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: If statement

Post by doubledave22 » 22 Jun 2021, 10:37

The parenthesis make the "If" use expression syntax. Either remove the parenthesis or add quotes around your "a".

check out: https://www.autohotkey.com/docs/commands/IfExpression.htm

either of these could work.

Code: Select all

If SingleKey = a

Code: Select all

If (SingleKey = "a")
Gurthen
Posts: 4
Joined: 03 Mar 2018, 11:54

Re: If statement

Post by Gurthen » 22 Jun 2021, 11:22

Thanks for the help!

Reading the documentation and changing like you said now works the other way around

Code: Select all

    Input, SingleKey, C, a,b ; Wait for Murgee to finish
    ;----- ShortCut
    If (SingleKey = "a")
{
....
}
    Else If (SingleKey = "b")
{
...
}
Now if I press 'a' nothing happens
image.png
image.png (91.94 KiB) Viewed 413 times
But if I press 'b' it does the b logic
image.png
image.png (54.47 KiB) Viewed 413 times
Can't seem to make both if work
Gurthen
Posts: 4
Joined: 03 Mar 2018, 11:54

Re: If statement

Post by Gurthen » 22 Jun 2021, 12:03

Ok found the problem... was with the input syntax

Input, SingleKey, C, , a,b ; Wait for Murgee to finish

wasn't passing one parameter :)
Post Reply

Return to “Ask for Help (v1)”