coord color reading

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ozne1
Posts: 2
Joined: 30 Jun 2022, 16:46

coord color reading

Post by ozne1 » 30 Jun 2022, 16:58

so, first time doing something more complex, wanted to learn to use the coord color reading, but I'm lost here.
if I have this as a basis

Code: Select all

^a::
T := !T
If T
 
else
 rest
return
this one is a simple toggle, where pressing ctrl+A starts or stops it right?

what I want is for when the pixel at coord X,Y becomes full black (#000000) it presses arrow down 3 times, then press Z, but if the pixel at Y,Z becomes full black it instead presses X followed by holding left arrow for 5 seconds. if none of those happen it just waits

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

Re: coord color reading

Post by mikeyww » 30 Jun 2022, 17:13

Welcome to this AutoHotkey forum!

Code: Select all

#MaxThreadsPerHotkey 2

x = 300
y = 300
z = 400

^a::
on := !on
Loop {
 Sleep, 200
 SoundBeep, 1900
 PixelGetColor, bgr, x, y
 If !bgr {
  Send {Down 3}z
  SoundBeep, 1500
  MouseMove, x, y ; Coordinates relative to active window
 } Else {
  PixelGetColor, bgr, y, z
  If bgr
   Continue
  Send x{Left down}
  Sleep, 5000
  Send {Left up}
  SoundBeep, 1000
  MouseMove, y, z
 }
} Until !bgr || !on
on := False
Return

ozne1
Posts: 2
Joined: 30 Jun 2022, 16:46

Re: coord color reading

Post by ozne1 » 02 Jul 2022, 21:35

mikeyww wrote:
30 Jun 2022, 17:13
Welcome to this AutoHotkey forum!

Code: Select all

#MaxThreadsPerHotkey 2

x = 300
y = 300
z = 400

^a::
on := !on
Loop {
 Sleep, 200
 SoundBeep, 1900
 PixelGetColor, bgr, x, y
 If !bgr {
  Send {Down 3}z
  SoundBeep, 1500
  MouseMove, x, y ; Coordinates relative to active window
 } Else {
  PixelGetColor, bgr, y, z
  If bgr
   Continue
  Send x{Left down}
  Sleep, 5000
  Send {Left up}
  SoundBeep, 1000
  MouseMove, y, z
 }
} Until !bgr || !on
on := False
Return
ok, so I think I understood it, and tried using on something else:

Code: Select all

#MaxThreadsPerHotkey 2

x = 619
y = 715
z = 997
w = 394

^a::
on := !on
Loop {
 Sleep, 200
 SoundBeep, 1900
 PixelGetColor, bgr, x, y
 If !bgr {
  Send {Down 3}
  sleep 100
  Send {Down 3}
  sleep 100
  Send {Down 3}
  sleep 100
  send z
  SoundBeep, 1500
  MouseMove, x, y ; Coordinates relative to active window
  bgr := 111111
 } Else {
  PixelGetColor, bgr, z, w
   continue
  If (bgr := 935046z) {
  Send x{Left down}
  Sleep, 1000
  Send {Left up}
  SoundBeep, 1000
  MouseMove, z, w
  bgr := 111111
  }
 }
} Until !on
on := False
Return
this is what I got, out of yours. I didn't want it to stop once it executed once, so I got rid of the "until !bgr", the send down was too fast to be registered properly, so I improvised with many commands and sleeps. lastly, I wanted scenario 2 to play only when an specific color appeared at an specific spot, but I either can't trigger anything below the else, or they get activated all the time that scenario 1 is not running. can't get it to work.
in short, it loops checking if point A is black and if point B is red, constantly, until I tell it to stop. if A is true, down 3 z (working), if B is true press and hold left for a short while. if none of those are true, just keep looping until they are, or until I tell it to stop.

anyways, thanks for the answer and sorry for the delay. @mikeyww

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: coord color reading

Post by boiler » 02 Jul 2022, 21:42

There are two things wrong with this line:

Code: Select all

  If (bgr := 935046z) {
One problem is the := operator is for assignment, not for comparison. The = sign is for comparison.

The other issue is 935046z is not valid a color value. It has one too many digits, z isn’t a valid hex digit, and you didn’t precede it with 0x to indicate it’s a hex value. The color value in BGR would be 0x935046 (shown in its actual color).

Post Reply

Return to “Ask for Help (v1)”