Page 1 of 1

*PixelGetColor* it's stopping with any key pressed

Posted: 03 Dec 2018, 22:29
by Education
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

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

Posted: 04 Dec 2018, 01:46
by Rohwedder
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

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

Posted: 04 Dec 2018, 07:57
by Education
@Rohwedder

Thank you for your attention. But like I said, removing return from each send command and it will run slowly.

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

Posted: 04 Dec 2018, 14:49
by Education
Up!

Guys, any idea?

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

Posted: 05 Dec 2018, 10:27
by Education
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?

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

Posted: 05 Dec 2018, 15:22
by Education
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

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

Posted: 06 Dec 2018, 00:24
by Rohwedder
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

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

Posted: 06 Dec 2018, 00:26
by Education
@Rohwedder

Ty dude! God bless you!