Sign in to follow this  
Followers 0
SXGuy

How can i Loop Send key variables?

6 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Is there no one who can give any advice at all???

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

EDIT:

i took what you suggested, and edited it, with a few things, and now works perfectly

thanks for your help

Edited by SXGuy

Share this post


Link to post
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
Sign in to follow this  
Followers 0