Sign in to follow this  
Followers 0
Fly By Night

Problem Handling Keypresses In A Loop

8 posts in this topic

Hi

I had the following in a For .. Next loop before but had to revert to this long method due to it sending wrong keypresses.

Here is the code,

Func SBAuto()
    $i = 1;
    Sleep(4500)
    Send("{NUMPAD0}")
    Sleep($annDelay)
    
    If $yourpos <> 1 Then
        Send("{NUMPAD1}")
        Sleep(500)
        Send("{NUMPAD1}")
        Sleep(4500)
    EndIf
    If $yourpos <> 2 Then
        Send("{NUMPAD2}")
        Sleep(500)
        Send("{NUMPAD2}")
        Sleep(4500)
    EndIf
    If $yourpos <> 3 Then
        Send("{NUMPAD3}")
        Sleep(500)
        Send("{NUMPAD3}")
        Sleep(4500)
    EndIf
    If $yourpos <> 4 Then
        Send("{NUMPAD4}")
        Sleep(500)
        Send("{NUMPAD4}")
        Sleep(4500)
    EndIf
    If $yourpos <> 5 Then
        Send("{NUMPAD5}")
        Sleep(500)
        Send("{NUMPAD5}")
        Sleep(4500)
    EndIf
    If $yourpos <> 6 Then
        Send("{NUMPAD6}")
        Sleep(500)
        Send("{NUMPAD6}")
        Sleep(4500)
    EndIf
    If $yourpos <> 7 Then
        Send("{NUMPAD7}")
        Sleep(500)
        Send("{NUMPAD7}")
        Sleep(4500)
    EndIf
    If $yourpos <> 8 Then
        Send("{NUMPAD8}")
        Sleep(500)
        Send("{NUMPAD8}")
    EndIf
    
    Sleep(80000)
EndFunc  ;==>SBAuto

Before I was using something like this which might be slighty out as wiped what i had :think:

Func SBAuto2()

    Sleep(4500)
    Send("{NUMPAD0}")
    Sleep($annDelay)
    
    For $i = 1 to 8 Step 1
        $temp = """{NUMPAD" & $i & "}"""
        If $yourpos <> $1 Then
            Send($temp)
            Sleep(500)
            Send($temp)
            Sleep(4500)
        EndIf
    Next

    Sleep(80000)
EndFunc

It was making up the NUMPAD1 to 8 alright as I had a label up changing as it went up the loop. For some reason though it kept sending weird things to program and it didn't run as intended. Seemed to keep sending NUMPAD2 a lot.

Can anyone see what might have gone wrong in the loop and why I had to go back to the "Long" version?

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$temp = """{NUMPAD" & $i & "}"""

Why do you use so many " ?

$temp = "{NUMPAD" & $i & "}"

is probably enough.

Edited by Manadar

Share this post


Link to post
Share on other sites

just add

While 1
SBAuto()
Sleep(1)
Wend

to the top of your script ( above it )

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I understood from his post he did not simply ment "How to loop my function?" . His question should be: What's wrong with the second code?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I used

$temp = """{NUMPAD" & $i & "}"""

as the Send command takes Send("{Numpad1}")

Using $temp = "{NUMPAD" & $i & "}" would make it Send({Numpad1})

Also I made a mistake in the SBAuto2 function,

If $yourpos <> $1 Then

should be

If $yourpos <> $i Then

I know about this so you don't need to tell me that. :think:

Cheers for the help so far. I can't see what i've done wrong as it is running Send with the right value so that's why I came to the forums.

Plus yes sorry I'm asking why the loop is not behaving. I'm calling it ok this is just the function that didn't behave as planned.

Edited by Fly By Night

Share this post


Link to post
Share on other sites

maybe this

Run("notepad")

Dim $annDelay = 10, $yourpos = 0

While $yourpos < 8
    
    $yourpos = $yourpos + 1
    
    SBAuto2()
    Send("{ENTER}")
    SBAuto()
    Send("{ENTER 2}")
    
WEnd



Func SBAuto2()

    Sleep(450)
    Send("{NUMPAD0}")
    Sleep($annDelay)
    
    For $i = 1 to 8 Step 1
        $temp = "{NUMPAD" & $i & "}"
        If $yourpos <> $i Then
            Send($temp)
            Sleep(50)
            Send($temp)
            Sleep(450)
        EndIf
    Next

   ;Sleep(80000); commented out
EndFunc


Func SBAuto()
    $i = 1;
    Sleep(450)
    Send("{NUMPAD0}")
    Sleep($annDelay)
    
    If $yourpos <> 1 Then
        Send("{NUMPAD1}")
        Sleep(50)
        Send("{NUMPAD1}")
        Sleep(450)
    EndIf
    If $yourpos <> 2 Then
        Send("{NUMPAD2}")
        Sleep(50)
        Send("{NUMPAD2}")
        Sleep(450)
    EndIf
    If $yourpos <> 3 Then
        Send("{NUMPAD3}")
        Sleep(50)
        Send("{NUMPAD3}")
        Sleep(450)
    EndIf
    If $yourpos <> 4 Then
        Send("{NUMPAD4}")
        Sleep(50)
        Send("{NUMPAD4}")
        Sleep(450)
    EndIf
    If $yourpos <> 5 Then
        Send("{NUMPAD5}")
        Sleep(50)
        Send("{NUMPAD5}")
        Sleep(450)
    EndIf
    If $yourpos <> 6 Then
        Send("{NUMPAD6}")
        Sleep(50)
        Send("{NUMPAD6}")
        Sleep(450)
    EndIf
    If $yourpos <> 7 Then
        Send("{NUMPAD7}")
        Sleep(50)
        Send("{NUMPAD7}")
        Sleep(450)
    EndIf
    If $yourpos <> 8 Then
        Send("{NUMPAD8}")
        Sleep(50)
        Send("{NUMPAD8}")
    EndIf
    
   ; Sleep(80000)
EndFunc ;==>SBAuto

this test both functions and works fine

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Cheers I'll try that.

I see my $temp = """{NUMPAD" & $i & "}""" wasn't working after all :think: and $temp = "{NUMPAD" & $i & "}" does after all.

Maybe you dont need the quotes for the value when using a variable with Send().

Thanks again ....

Share this post


Link to post
Share on other sites

Welcome

8)


NEWHeader1.png

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