Jump to content

Multiple Step Loops (Send and Pixelsearch)


Travb
 Share

Recommended Posts

Hey again.

 

I'm trying to write this script that will do basic keystrokes and requires pixel search for it to be most effective.

This is what I'm trying to do:

Send {SPACE} until 0xFF0000 is found in rectangle 880,647,921,679

Then

Send("{DOWN down}")

sleep(50)

Send{"{DOWN up}")

Then

Send {SPACE} until 0xFF0000 is found in rectangle 880,647,921,679

Then

Send("{LEFT down}")

sleep(50)

Send("{LEFT up}")

Then I will Loop the whole thing with While and WEnd, but that will be useless until I can figure out how to write the middle section.
 

 

 

Heres the trash that I've come up with

$pixel = PixelSearch ( 880, 647, 921, 679, 0xFF0000 )

Func sendkey()
 If @error = True Then
 Send("{SPACE DOWN}")
 sleep(50)
EndFunc

While $pixel
 sendkey()
 If @error = False Then
 Send("{SPACE up}")
 sleep(50)
 Send("{DOWN up}")
 sleep(50)
 Send("{LEFT up}")
 sleep(50)
 EndIF
 send("{LEFT down}")
 sleep(50)
 Send("{LEFT up}")
 sleep(50)
 sendkey()
 If @error = False Then
 Send("{SPACE up}")
 sleep(50)
 Send("{DOWN up}")
 sleep(50)
 Send("{LEFT up}")
 sleep(50)
 send("{LEFT down}")
 sleep(50)
 send("{LEFT up}")
 
 WEnd

I have tried many versions of this but deleted all of them, I just wrote that one on the spot.

I haven't tried running that one yet, it seems like it wont work though.

While $UnPaused
       ToolTip("lesgo",0,0)

         Do
            Send("{SPACE down}")
            sleep(50)
            Send("{SPACE up}")
         Until $pixel = True
         If $pixel = True Then
            send("{SPACE up}")
            sleep(500)
            Send("{DOWN down}")
            sleep(50)
            Send("{DOWN up}")
         EndIf

            Do
               Send("{SPACE down}")
               sleep(50)
               Send("{SPACE up}")
            Until $pixel = True Then
            sleep(50)
            Send("{LEFT down}")
            sleep(50)
            Send("{LEFT up}")


WEnd

I tried that one as well, didn't work.

 

 

Edited by Travb
Link to comment
Share on other sites

Ehi Travb,

I don't have an image to test with, but the example below should work fine for you.

Substantially, instead of having multiple Loops, we have only 1 main Loop and we change the "action" based on a variable, hope it's clear for you.

Cheers,
Luciano

Local $var=0    ; We start with Variation 0
While 1
   Send("{SPACE}")  ; Spam SPACE button until we find color Red
   Sleep(500)
   Local $coord = PixelsSearch(880, 647, 921, 679, 0xFF0000)    ; Search for Red in the rectangle
   If @error=-1 Then    ; If color Red is found
      IF $var = 0   ; If $var is 0 press Down
         Send("{DOWN down}")
         Sleep(50)
         Send{"{DOWN up}")
         $var = 1   ; Change $var
      Else  ; If $var is 0 press Down
         Send("{LEFT down}")
         Sleep(50)
         Send("{LEFT up}")
         $var = 0 ; Change $var
      EndIf
   EndIf
WEnd

 

Edited by r3dbullo88
Link to comment
Share on other sites

11 hours ago, r3dbullo88 said:

Ehi Travb,

I don't have an image to test with, but the example below should work fine for you.

Substantially, instead of having multiple Loops, we have only 1 main Loop and we change the "action" based on a variable, hope it's clear for you.

Cheers,
Luciano

Local $var=0    ; We start with Variation 0
While 1
   Send("{SPACE}")  ; Spam SPACE button until we find color Red
   Sleep(500)
   Local $coord = PixelsSearch(880, 647, 921, 679, 0xFF0000)    ; Search for Red in the rectangle
   If @error=-1 Then    ; If color Red is found
      IF $var = 0   ; If $var is 0 press Down
         Send("{DOWN down}")
         Sleep(50)
         Send{"{DOWN up}")
         $var = 1   ; Change $var
      Else  ; If $var is 0 press Down
         Send("{LEFT down}")
         Sleep(50)
         Send("{LEFT up}")
         $var = 0 ; Change $var
      EndIf
   EndIf
WEnd

 

Eveything seems right, I'll try this when I get home.

Link to comment
Share on other sites

Alright, so I ran the script and I got exit code 0

I added a little bit to the script and fixed a few typos

HotKeySet("2", "TogglePause")

Func TogglePause()
   Local $var=0    ; We start with Variation 0
While 1
   Send("{SPACE}")  ; Spam SPACE button until we find color Red
   Sleep(500)
   Local $coord = PixelSearch(880, 647, 921, 679, 0xFF0000)    ; Search for Red in the rectangle
   If @error=-1 Then    ; If color Red is found
      IF $var = 0 Then ; If $var is 0 press Down
         Send("{DOWN down}")
         Sleep(50)
         Send("{DOWN up}")
         $var = 1   ; Change $var
      Else  ; If $var is 0 press Down
         Send("{LEFT down}")
         Sleep(50)
         Send("{LEFT up}")
         $var = 0 ; Change $var
      EndIf
   EndIf
WEnd
EndFunc

Not sure why I'm getting this error.

Link to comment
Share on other sites

I'm not 100% sure, but you can try this way: (Changed @error check condition)
HotKeySet("2", "TogglePause")

Func TogglePause()
   Local $var=0    ; We start with Variation 0
While 1
   Send("{SPACE}")  ; Spam SPACE button until we find color Red
   Sleep(500)
   Local $coord = PixelSearch(880, 647, 921, 679, 0xFF0000)    ; Search for Red in the rectangle
   If Not @error Then    ; If color Red is found
      IF $var = 0 Then ; If $var is 0 press Down
         Send("{DOWN down}")
         Sleep(50)
         Send("{DOWN up}")
         $var = 1   ; Change $var
      Else  ; If $var is 0 press Down
         Send("{LEFT down}")
         Sleep(50)
         Send("{LEFT up}")
         $var = 0 ; Change $var
      EndIf
   EndIf
WEnd
EndFunc

 

Link to comment
Share on other sites

On 20/10/2016 at 1:16 PM, Bert said:

Guys - Is there some reason to not simply hook into the control? PixelSearch is horrible to use.

There's no control, besides I need to detect the pixel, I can't just set a specify a time for the key sends.

Link to comment
Share on other sites

On 10/20/2016 at 5:16 AM, Bert said:

Guys - Is there some reason to not simply hook into the control? PixelSearch is horrible to use.

lol.

 

2 hours ago, Travb said:

There's no control, besides I need to detect the pixel, I can't just set a specify a time for the key sends.

what game is this?

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

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...