1
votes

I'm writing a script for AHK which automate few things in my MMORPG game. I want to perform 2 different automation when F2 or F3 is pressed.

Sometimes this script is with interaction with another action from keyboard/mouse so I need to suspend script when one of the following keys is pressed: 2,3,4,5,E,R

But when I press 1 the script need to be unsuspended.

I was trying many different options but I can't write it. I can't even google anything similiar.

My code looks like that:

  key_a:="F2"
key_b:="F3"

loop {
sleep 1

if GetKeyState(key_a) {
    a:=true
    b:=false
}

if GetKeyState(key_b) {
    a:=false
    b:=true
}

if a {
    MsgBox, Do something
}

if b {
    MsgBox, Do somethiung else
}
}

This script language is bit strange for me.

Can you help me. Thanks

1

1 Answers

1
votes

Try:

key_a:="F2"
key_b:="F3"

SetTimer, keyStates, 100

KeyStates: ; SubRoutine
    if GetKeyState(key_a, "P") {
            a:=true
            b:=false
    }

    if GetKeyState(key_b, "P") {
        a:=false
        b:=true
    }

    if a {
        ToolTip, F2 is doing something
    }

    if b {
        ToolTip, F3 is Doing Something!
    }
return 

2::
3::
4::
5::
E::
R::SetTimer, keyStates, Off

1::SetTimer, keyStates, on