*PixelGetColor* it's stopping with any key pressed

Ask gaming related questions (AHK v1.1 and older)
Education
Posts: 6
Joined: 03 Dec 2018, 22:05

*PixelGetColor* it's stopping with any key pressed

03 Dec 2018, 22:29

Greetings!

It's working perfectly, but it's stopping with any key pressed.

If I remove return from each send command, the problem disapear. But I lost a lot speed doing that. So I need to keep it.

Dear friends, do you have any idea?

Thank you!

Code: Select all

#NoEnv
#KeyHistory 0
#SingleInstance, Force
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetWinDelay, -1
ListLines Off
SendMode Input
CoordMode, Pixel, Window

$1::
	While (GetKeyState("1", "P")) {
	PixelGetColor, color, 1227, 1289, RGB
	If color = 0x726408
	{
	Send, 1
	return
	}
	PixelGetColor, color, 1249, 1254, RGB
	If color = 0xE99D16
	{
	Send, 2
	return
	}
	PixelGetColor, color, 1245, 1257, RGB
	If color = 0xDBD29A
	{
	Send, 3
	return
	}
	PixelGetColor, color, 1256, 1276, RGB
	If color = 0x33B7BA
	{
	Send, 4
	return
	}
	PixelGetColor, color, 1237, 1273, RGB
	If color = 0xFFF063
	{
	Send, 5
	return
	}
	PixelGetColor, color, 1251, 1275, RGB
	If color = 0x532010
	{
	Send, 6
	return
	}
	PixelGetColor, color, 1238, 1274, RGB
	If color = 0xCCBD82
	{
	Send, 7
	return
	}
	PixelGetColor, color, 1269, 1274, RGB
	If color = 0xFCEE72
	{
	Send, 8
	return
	}
	PixelGetColor, color, 1230, 1253, RGB
	If color = 0x00092B
	{
	Send, 9
	return
	}
}
Return
Last edited by Education on 05 Dec 2018, 10:22, edited 1 time in total.
Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: *PixelGetColor* it's stopping with any key pressed

04 Dec 2018, 01:46

Hallo,
I added a counter to your While loop. You command Autohotkey 100% of its time to check pixels and then wonder why it doesn't have time for other things?
If you press another hotkey the While loop will be paused as long as the other thread is ready.

Code: Select all

#NoEnv
#KeyHistory 0
#SingleInstance, Force
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetWinDelay, -1
ListLines Off
SendMode Input
CoordMode, Pixel, Window
$1::
	While (GetKeyState("1", "P")) {
	No++
	ToolTip,% No
	PixelGetColor, color, 1227, 1289, RGB
	If color = 0x726408
	{
	Send, 1
	}
	PixelGetColor, color, 1249, 1254, RGB
	If color = 0xE99D16
	{
	Send, 2
	}
	PixelGetColor, color, 1245, 1257, RGB
	If color = 0xDBD29A
	{
	Send, 3
	}
	PixelGetColor, color, 1256, 1276, RGB
	If color = 0x33B7BA
	{
	Send, 4
	}
	PixelGetColor, color, 1237, 1273, RGB
	If color = 0xFFF063
	{
	Send, 5
	}
	PixelGetColor, color, 1251, 1275, RGB
	If color = 0x532010
	{
	Send, 6
	}
	PixelGetColor, color, 1238, 1274, RGB
	If color = 0xCCBD82
	{
	Send, 7
	}
	PixelGetColor, color, 1269, 1274, RGB
	If color = 0xFCEE72
	{
	Send, 8
	}
	PixelGetColor, color, 1230, 1253, RGB
	If color = 0x00092B
	{
	Send, 9
	}
}
Return
Education
Posts: 6
Joined: 03 Dec 2018, 22:05

Re: *PixelGetColor* it's stopping with any key pressed

04 Dec 2018, 07:57

@Rohwedder

Thank you for your attention. But like I said, removing return from each send command and it will run slowly.
Education
Posts: 6
Joined: 03 Dec 2018, 22:05

Re: *PixelGetColor* it's stopping with any key pressed

05 Dec 2018, 10:27

Sorry. I'm retarded. I forgot the return

I edited and added the return

Any idea how can I press other key without break the loop?
Education
Posts: 6
Joined: 03 Dec 2018, 22:05

Re: *PixelGetColor* it's stopping with any key pressed

05 Dec 2018, 15:22

I tried this. But it's still slow. Please, some good soul help me! I would really appreciate.

Code: Select all

#NoEnv
#KeyHistory 0
#SingleInstance, Force
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetWinDelay, -1
ListLines Off
SetWorkingDir %A_ScriptDir%
SendMode Input
CoordMode, Pixel, Window
posX := [1227,1249,1245,1256,1237,1251,1238,1269,1230]
posY := [1289,1254,1257,1276,1273,1275,1274,1274,1253]
clr := ["0x726408","0xE99D16","0xDBD29A","0x33B7BA","0xFFF063","0x532010","0xCCBD82","0xFCEE72","0x00092B"]
char := ["1","2","3","4","5","6","7","8","9"]
$1::
While (GetKeyState("1", "P"))
Loop 9	{
	PixelGetColor, color, posX[A_Index], posY[A_Index], RGB
	if (color = clr[A_Index])
	{
	SendInput % char[A_Index]
	}
}
return
Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: *PixelGetColor* it's stopping with any key pressed

06 Dec 2018, 00:24

Hallo,
I slightly trimmed your script and replaced the while loop with a timing loop.
One color cycle lasts here 47 - 63 µs. Well, I find that's very fast!

Code: Select all

#NoEnv
#KeyHistory 0
#SingleInstance, Force
Process, Priority, , H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetWinDelay, -1
ListLines Off
SetWorkingDir %A_ScriptDir%
SendMode Input
CoordMode, Pixel, Window
posX := [1227,1249,1245,1256,1237,1251,1238,1269,1230]
posY := [1289,1254,1257,1276,1273,1275,1274,1274,1253]
clr := [0x726408,0xE99D16,0xDBD29A,0x33B7BA,0xFFF063,0x532010,0xCCBD82,0xFCEE72,0x00092B]
$1::
T := A_TickCount
loop, 1000 ;While GetKeyState("1", "P")
Loop 9	{
	PixelGetColor, color, posX[A_Index], posY[A_Index], RGB
	if (color = clr[A_Index])
		SendInput % A_Index
}
ToolTip,% (A_TickCount-T) " µs per colour cycle"
KeyWait, 1
ToolTip
return
Education
Posts: 6
Joined: 03 Dec 2018, 22:05

Re: *PixelGetColor* it's stopping with any key pressed

06 Dec 2018, 00:26

@Rohwedder

Ty dude! God bless you!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 72 guests