Page 1 of 1

Help with Pixelsearch Script

Posted: 30 Nov 2022, 21:22
by geschenkepaket
Hey guys, i a little bit new to AHK, so i did this script and it worked for me but now i want: if this Pixel is not appear after 20 seconds the script should Press "F3" then "F4"
and restart the script.

Code: Select all

Loop
{
    CoordMode, Pixel, Screen
    PixelSearch, FoundX, FoundY, 753, 21, 1133, 322, 0xEBE7EC, 0, Fast RGB
    If (ErrorLevel = 0)
    {
  sleep 2900
	Send, {F4 down}
	Sleep 10
	Send, {F4 up}
	Sleep 30
	MouseMove, 1134, 904
	Sleep 30
	Click Right
	Sleep 30
	Send, {F3 down}
	Sleep 10
	Send, {F3 up}
	Sleep 30
	Send, {F4 down}
	Sleep 10
	Send, {F4 up}
	Send, {Q down}
	Sleep 5000
	Send, {Q up}
    }
}
Return

Re: Help with Pixelsearch Script

Posted: 30 Nov 2022, 22:36
by mikeyww
Welcome to this AutoHotkey forum!

Code: Select all

#SingleInstance Force
CoordMode, Pixel
Loop {
 SoundBeep, 1500
 end := A_TickCount + 20000
 While (A_TickCount < end) {
  Sleep, 50
  PixelSearch,,, 753, 21, 1133, 322, 0xEBE7EC,, Fast RGB
  If !ErrorLevel {
   MsgBox, 64, Found, Found!
   Return
  }
 }
 Send {F3}{F4}
}

Re: Help with Pixelsearch Script

Posted: 01 Dec 2022, 16:39
by geschenkepaket
mikeyww wrote:
30 Nov 2022, 22:36
Welcome to this AutoHotkey forum!

Code: Select all

#SingleInstance Force
CoordMode, Pixel
Loop {
 SoundBeep, 1500
 end := A_TickCount + 20000
 While (A_TickCount < end) {
  Sleep, 50
  PixelSearch,,, 753, 21, 1133, 322, 0xEBE7EC,, Fast RGB
  If !ErrorLevel {
   MsgBox, 64, Found, Found!
   Return
  }
 }
 Send {F3}{F4}
}
Hey thx :)
I may have explained it wrong,
so the script should repeat itself whenever the pixel appears on XY.
But if this pixel does not appear after 20 seconds, it should press "F3" then "F4" and repeat the entire script.

Re: Help with Pixelsearch Script

Posted: 01 Dec 2022, 17:12
by mikeyww

Code: Select all

#SingleInstance Force
CoordMode, Pixel
Loop {
 SoundBeep, 1500
 end := A_TickCount + 20000, x := ""
 While (A_TickCount < end && x = "") {
  Sleep, 50
  PixelSearch, x,, 753, 21, 1133, 322, 0xEBE7EC,, Fast RGB
 }
 Send % x = "" ? "{F3}{F4}" : ""
}

Re: Help with Pixelsearch Script

Posted: 01 Dec 2022, 18:11
by geschenkepaket
mikeyww wrote:
01 Dec 2022, 17:12

Code: Select all

#SingleInstance Force
CoordMode, Pixel
Loop {
 SoundBeep, 1500
 end := A_TickCount + 20000, x := ""
 While (A_TickCount < end && x = "") {
  Sleep, 50
  PixelSearch, x,, 753, 21, 1133, 322, 0xEBE7EC,, Fast RGB
 }
 Send % x = "" ? "{F3}{F4}" : ""
}
Im sorry but i dont understand what u did there :D Can you maybe explain it at my Script ?
Im a little bit new at AHK :)

Re: Help with Pixelsearch Script

Posted: 01 Dec 2022, 18:45
by mikeyww
I added comments. I have written the script based on a vague description of the need, so you might need to adjust it to meet your needs. It demonstrates looping, conditional statements, and sending keys. In this example, instead of using the ErrorLevel, the x-coordinate that is returned is used. This value is non-null if the search succeeds, null if it fails.

Code: Select all

#SingleInstance Force
CoordMode, Pixel
Loop {
 SoundBeep, 1500
 end := A_TickCount + 20000, x := ""
 While (A_TickCount < end && x = "") { ; Time-limited loop while pixel is not found
  Sleep, 50
  PixelSearch, x,, 753, 21, 1133, 322, 0xEBE7EC,, Fast RGB
 }
 Send % x = "" ? "{F3}{F4}" : ""       ; If pixel is not found in time-limited loop, send F3 F4
}                                      ; Continue the outer loop

Re: Help with Pixelsearch Script

Posted: 02 Dec 2022, 03:40
by geschenkepaket
mikeyww wrote:
01 Dec 2022, 18:45
I added comments. I have written the script based on a vague description of the need, so you might need to adjust it to meet your needs. It demonstrates looping, conditional statements, and sending keys. In this example, instead of using the ErrorLevel, the x-coordinate that is returned is used. This value is non-null if the search succeeds, null if it fails.

Code: Select all

#SingleInstance Force
CoordMode, Pixel
Loop {
 SoundBeep, 1500
 end := A_TickCount + 20000, x := ""
 While (A_TickCount < end && x = "") { ; Time-limited loop while pixel is not found
  Sleep, 50
  PixelSearch, x,, 753, 21, 1133, 322, 0xEBE7EC,, Fast RGB
 }
 Send % x = "" ? "{F3}{F4}" : ""       ; If pixel is not found in time-limited loop, send F3 F4
}                                      ; Continue the outer loop
Okay, but i dont understand where i have to add my Sending keys from the script before.

Re: Help with Pixelsearch Script

Posted: 02 Dec 2022, 06:35
by mikeyww

Code: Select all

#SingleInstance Force
CoordMode, Pixel
Start:
Loop {
 end := A_TickCount + 20000
 While (A_TickCount < end) {
  Sleep, 50
  PixelSearch,,, 753, 21, 1133, 322, 0xEBE7EC,, Fast RGB
  If !ErrorLevel {
   Send a
   Send b
   Send ...
   Continue, Start
  }
 }
 Send {F3}{F4}
}