Help with Pixelsearch Script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
geschenkepaket
Posts: 4
Joined: 30 Nov 2022, 21:14

Help with Pixelsearch Script

Post by geschenkepaket » 30 Nov 2022, 21:22

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

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help with Pixelsearch Script

Post by mikeyww » 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}
}

geschenkepaket
Posts: 4
Joined: 30 Nov 2022, 21:14

Re: Help with Pixelsearch Script

Post by geschenkepaket » 01 Dec 2022, 16:39

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.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help with Pixelsearch Script

Post by mikeyww » 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}" : ""
}

geschenkepaket
Posts: 4
Joined: 30 Nov 2022, 21:14

Re: Help with Pixelsearch Script

Post by geschenkepaket » 01 Dec 2022, 18:11

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 :)

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help with Pixelsearch Script

Post by mikeyww » 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

geschenkepaket
Posts: 4
Joined: 30 Nov 2022, 21:14

Re: Help with Pixelsearch Script

Post by geschenkepaket » 02 Dec 2022, 03:40

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.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help with Pixelsearch Script

Post by mikeyww » 02 Dec 2022, 06:35

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

Post Reply

Return to “Ask for Help (v1)”