Help PixelSearch!!

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ImLuxy_
Posts: 3
Joined: 22 Mar 2023, 14:25

Help PixelSearch!!

Post by ImLuxy_ » 22 Mar 2023, 14:45

When I press the LButton the pointer goes looking for a specific color, but if I have the same color on multiple points of the screen it goes crazy, how could I specify to focus exclusively on smaller pixels? or in the center of the screen?
this is the code

Code: Select all

init:
#NoEnv
#SingleInstance, Force
#Persistent
#InstallKeybdHook
#UseHook
#KeyHistory, 0
#HotKeyInterval 1
#MaxHotkeysPerInterval 127
traytip,
SetKeyDelay, -1, 1
SetControlDelay, -1
SetMouseDelay, -1
SetWinDelay, -1
SendMode, InputThenPlay
SetBatchLines, -1
ListLines, Off
CoordMode, Pixel, Screen, RGB
CoordMode, Mouse, Screen
PID := DllCall("GetCurrentProcessId")
Process, Priority, %PID%, High

EMCol := 0xc9008d
ColVn := 1
ZeroX := 955
ZeroY := 500
CFovX := 200
CFovY := 200
ScanL := ZeroX - CFovX
ScanT := ZeroY - CFovY
ScanR := ZeroX + CFovX
ScanB := ZeroY + CFovY

targetX := 40
targetY := 40



Loop, {
  targetFound := False
  
  if GetKeyState("LButton", "P") or GetKeyState("RButton", "P") {
    ; search for target pixel in a smaller region around the last known position
    PixelSearch, AimPixelX, AimPixelY, targetX-40, targetY-40, targetX+40, targetY+40, EMCol, ColVn, Fast RGB
    
    if (!ErrorLevel) {
      targetX := AimPixelX
      targetY := AimPixelY
      targetFound := True
    } else {
      PixelSearch, AimPixelX, AimPixelY, ScanL, ScanT, ScanR, ScanB, EMCol, ColVn, Fast RGB
      if (!ErrorLevel) {
        targetX := AimPixelX
        targetY := AimPixelY
        targetFound := True
      }
    }
    
    if (targetFound) {
      AimX := targetX - ZeroX
      AimY := targetY - ZeroY
      DirX := -0.5
      DirY := -0.5
      if ( AimX > 0 ) {
        DirX := 0.5
      }
      if ( AimY > 0 ) {
        DirY := 0.5
      }
      AimOffsetX := AimX * DirX
      AimOffsetY := AimY * DirY
      MoveX := Floor(( AimOffsetX ** ( 1 / 2 ))) * DirX
      MoveY := Floor(( AimOffsetY ** ( 1 / 2 ))) * DirY
      ;DllCall ( "mouse_event" , uint , 1 , int , MoveX * 0.5 , int , MoveY , uint , 0 , int , 0 )       
      DllCall("mouse_event", uint, 1, int , MoveX * 0.5 , int , MoveY , uint , 0 , int , 0)
     ;DllCall("mouse_event", uint, 1, int, 0, int, CursorOffset, uint, 0, int, 0)
    }
  }
}

toggle := false

; Hotkey to toggle on/off
\::
    toggle := !toggle
    if (toggle) {
        SoundBeep, 800, 400
    }
    return


if (targetFound && toggle) {
    click down
} else {
    click up
}

Paused := False
e::
Pause
Paused := !Paused
if (Paused) {
    SoundBeep, 750, 500
}
Return

[Mod actions: Moved to v1 section because posted code is v1. The main section is for v2. Added [code][/code] tags. Please use them yourself when posting code.]

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

Re: Help PixelSearch!!

Post by mikeyww » 22 Mar 2023, 19:49

Welcome to this AutoHotkey forum!

PixelSearch allows you specify any coordinates you like, so you can just change them. The screen dimensions for the primary monitor are A_ScreenWidth x A_ScreenHeight.

ImLuxy_
Posts: 3
Joined: 22 Mar 2023, 14:25

Re: Help PixelSearch!!

Post by ImLuxy_ » 24 Mar 2023, 14:38

mikeyww wrote:
22 Mar 2023, 19:49
Welcome to this AutoHotkey forum!

PixelSearch allows you specify any coordinates you like, so you can just change them. The screen dimensions for the primary monitor are A_ScreenWidth x A_ScreenHeight.
Hi, could you edit the script yourself? I don't know how to apply the change

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

Re: Help PixelSearch!!

Post by mikeyww » 24 Mar 2023, 19:06

You can learn how the PixelSearch command works by clicking on the command name in the posted script. That command has the coordinates that should be searched. You would change those coordinates to be whatever region you would like to be searched.

ImLuxy_
Posts: 3
Joined: 22 Mar 2023, 14:25

Re: Help PixelSearch!!

Post by ImLuxy_ » 25 Mar 2023, 12:55

mikeyww wrote:
24 Mar 2023, 19:06
You can learn how the PixelSearch command works by clicking on the command name in the posted script. That command has the coordinates that should be searched. You would change those coordinates to be whatever region you would like to be searched.
do you know if there is a way to tell the script to read a range between e.g. 10 and 20 pixels? neither smaller nor bigger?

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

Re: Help PixelSearch!!

Post by mikeyww » 25 Mar 2023, 13:52

Yes. Your coordinates can cover whatever range you like. An example of a specific range is found on line 44 of your script.

Post Reply

Return to “Ask for Help (v1)”