Besides using something else other than
PixelGetColor to query pixel data?
How you've structured your script incurs a performance hit. You're first gathering all pixel colors, then start checking them iteratively to figure out what commands to carry out next. Those command appear to be mutually exclusive wrt. each other, as indicated by the
breaks. So why do the work of querying 10 times if there's a possibility that you'll break on the 1st or 2nd or 3rd, etc found pixel? Instead query the pixels as you need them.
Here's the unmaintainable copy paste version:
Code: Select all
#MaxThreadsPerHotkey 2
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
CoordMode, Pixel, Window
Toggle = 0
$2::
Toggle := !Toggle
While Toggle {
PixelGetColor, foundColor, 819, 850, RGB
if (foundColor = 0xFF0000)
{
Send, {Numpad2}
sleep 10
continue
}
PixelGetColor, foundColor, 885, 866, RGB
if (foundColor = 0xEED3C7)
{
Send, {Numpad3}
sleep 10
continue
}
PixelGetColor, foundColor, 925, 859, RGB
if (foundColor = 0xCA1008)
{
Send, {Numpad4}
sleep 10
continue
}
PixelGetColor, foundColor, 967, 859, RGB
if (foundColor = 0x52DC43)
{
Send, {Numpad5}
sleep 10
continue
}
PixelGetColor, foundColor, 851, 854, RGB
if (foundColor = 0x0A2A00)
{
Send, {Numpad6}
sleep 10
continue
}
Send {Numpad1}
sleep 10
}
return
maybe shove pixelsearch in a function and save yourself some hassle:
Code: Select all
#MaxThreadsPerHotkey 2
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
CoordMode, Pixel, Window
Toggle = 0
$2::
Toggle := !Toggle
While Toggle {
if (getColorAt(819, 850) = 0xFF0000)
{
Send, {Numpad2}
sleep 10
continue
}
if (getColorAt(885, 866) = 0xEED3C7)
{
Send, {Numpad3}
sleep 10
continue
}
if (getColorAt(925, 859) = 0xCA1008)
{
Send, {Numpad4}
sleep 10
continue
}
if (getColorAt(967, 859) = 0x52DC43)
{
Send, {Numpad5}
sleep 10
continue
}
if (getColorAt(851, 854) = 0x0A2A00)
{
Send, {Numpad6}
sleep 10
continue
}
Send {Numpad1}
sleep 10
}
return
getColorAt(x, y) {
PixelGetColor, foundColor, % x, % y, RGB ; try Fast RGB
return foundColor
}
for arbitrary number of colors:
Code: Select all
#MaxThreadsPerHotkey 2
#NoEnv
; #MaxHotkeysPerInterval 99000000 ; i
; #HotkeyInterval 99000000 ; wish
; #KeyHistory 0 ; this
; ListLines Off ; thread
; Process, Priority, , A ; would
SetBatchLines, -1
; SetKeyDelay, -1, -1 ; simply
; SetMouseDelay, -1 ; just
; SetDefaultMouseSpeed, 0 ; die
; SetWinDelay, -1 ; already,
; SetControlDelay, -1 ; jesus
SendMode Input
CoordMode, Pixel, Window
class ColorKey
{
__New(color, key, x, y)
{
this.color := color
this.key := key
this.x := x
this.y := y
}
}
ColorKeyMap := [new ColorKey(0xFF0000, "{Numpad2}", 819, 819)
, new ColorKey(0xEED3C7, "{Numpad3}", 885, 885)
, new ColorKey(0xCA1008, "{Numpad4}", 925, 925)
, new ColorKey(0x52DC43, "{Numpad5}", 967, 967)
, new ColorKey(0x0A2A00, "{Numpad6}", 851, 851)]
$2::
Toggle := !Toggle
while(Toggle)
{
for each, Element in ColorKeyMap
{
PixelGetColor, foundColor, % Element.x, % Element.y, RGB ; maybe try 'Fast RGB' also
if (Element.color = foundColor)
{
Send % Element.key
Sleep 10
continue 2 ; start a new iteration of the while loop
}
}
; script has survived the foreach gauntlet
; no colors were found, so send Num1 and start over
Send {Numpad1}
Sleep 10
}
return