Jump to content

How can i Loop Send key variables?


SXGuy
 Share

Recommended Posts

Can anyone tell me how can i set variables to each key send in a loop?

basically, i want to be able to send x and y until a variable and then send z, repeat.

$Wait is the variable for z.

So for example, if $Wait is 4 seconds, i would want to send X and Y for 4 seconds, and then Z once, then repeat the loop.

Ive included part of the script below, that i know would need to be changed

GUICtrlRead ($Wait)
While 1 
    Sleep(5) 
    
    if $AL = 1 then send("x") 
    if $AA = 1 then send("y")
    If $AS = 1 then send("z")
EndIf 
WEnd

Any ideas?

Edited by SXGuy
Link to comment
Share on other sites

Can anyone tell me how can i set variables to each key send in a loop?

basically, i want to be able to send x and y until a variable and then send z, repeat.

$Wait is the variable for z.

So for example, if $Wait is 4 seconds, i would want to send X and Y for 4 seconds, and then Z once, then repeat the loop.

Ive included part of the script below, that i know would need to be changed

GUICtrlRead ($Wait)
While 1 
    Sleep(5) 
    
    if $AL = 1 then send("x") 
    if $AA = 1 then send("y")
    If $AS = 1 then send("z")
EndIf 
WEnd

Any ideas?

Yeah you can do it like so:

For $i in myArray

 Send("{" & $i & "}")

Next
Link to comment
Share on other sites

i tried that, but it didnt work so well, either it sent whatever value my variable was along with the key, or it sent my variable in raw format.

I need my variable to cause a delay in a keypress, but still maintain the loop of sending other keypresses.

So if my script is

While 1

If A1 = 1 send ("x")

If A2 = send ("Y")

EndIf

WEnd

And the delay variable i want to use is in GUICtrlRead ($Wait).

As it stands, if i press the hotkey for x and y, it will send x and y together in a continously loop, which is fine, however, what if i want to make Y delay for a certain amount of time before it sends the key again BUT have x still being sent during that delay?

ive tried using $Wait as a Sleep variable, but that will make all keys being sent, delay until the end of $Wait, and thats not what i want, ive tried jumping out of the while statment to another function of the hotkey for Y is pressed, and then using an expression there, but it still has the same effect.

Link to comment
Share on other sites

So for example, if $Wait is 4 seconds, i would want to send X and Y for 4 seconds, and then Z once, then repeat the loop.

Just answering to that part.

HotKeySet('{esc}', 'quit')  ;exit the script with escape
HotKeySet('{F2}', 'toggle')  ;toggle the action with F2

$doit = False
$Wait = InputBox('', 'Enter time in seconds')

While 1
    While $doit
        $time = TimerInit()
        Do
            Send("x")
            Send("y")
            Sleep(50)
        Until TimerDiff($time) > $Wait * 1000
        Send("z")
    WEnd
    Sleep(50)
WEnd

Func toggle()
    $doit = Not $doit
EndFunc

Func quit()
    Exit
EndFunc

edit - forgot a sleep()

Edited by xcal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...