PixelGetColor Loop not working Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Jadden182
Posts: 21
Joined: 08 Jan 2021, 21:10

PixelGetColor Loop not working

07 Oct 2021, 10:00

I made this loop to check if a window is maximized and if it is to then check for a color in a specific spot on the page. If the color is there then i want it to block keyboard input. It detects the color just fine and block keyboard input but it doesn't start the loop again after it blocks keyboard input. I have attached where it gets stuck and it just stays there. Thanks in advance.

Code: Select all

#persistent
#SingleInstance Ignore

loop
{
	WinActivate, CMS Reporting
	sleep, 2000
	WinGet,WinState,MinMax, CMS Reporting
	If WinState =1 ; WinState = 1 if it's Maxxed
	{
		CoordMode, Pixel, Relative
		PixelGetColor, color, 1015, 790
		if color =0x00FF00 ; if green is found
		{
			Input, OutputVar, L9999 ; block keyboard input
			Continue
		}
		else if color !=0x00FF00 ; green is not found
		{
			F1::F2
		}
	}
	else
	{
		WinMaximize, CMS Reporting
	}
}
Return
Attachments
Capture.PNG
Capture.PNG (21.07 KiB) Viewed 944 times
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Loop not working

07 Oct 2021, 12:51

Exactly right. Before proceeding, the script is waiting for you to type 9,999 characters-- as you told it to do! You can use BlockInput as an alternative-- but very cautiously!
User avatar
Jadden182
Posts: 21
Joined: 08 Jan 2021, 21:10

Re: PixelGetColor Loop not working

07 Oct 2021, 14:19

It seems as if BlockInput disables both the mouse and the keyboard. I only want to disable the keyboard. Any other ideas? I really only need to block all numbers.
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Loop not working

07 Oct 2021, 14:54

You can use Hotkey to disable every key. viewtopic.php?p=405573#p405573

If you mean digits, it's easy enough to set a variable and then context-sensitive hotkeys for that variable.

Code: Select all

disabled := True

#If disabled
1::
2::
3::
4::
5::
6::
7::
8::
9::
0::Return
#If
Your line 20 will fail to work as you expect, but you can use the #If directive; see the documentation for a description & additional examples.

Code: Select all

WinWait, % winTitle := "CMS Reporting"
SetTimer, Check, 200
Loop {
 WinWaitNotActive
 If WinExist()
  WinActivate
 Else Return
}
Check:
WinGet, WinState, MinMax, %winTitle%
If (WinState = 1) ; Maximized
 PixelGetColor, color, 1015, 790
Else WinMaximize, %winTitle%
Return

#If (color = 0x00FF00)
1::
2::
3::
4::
5::
6::
7::
8::
9::
0::Return

#If (color != 0x00FF00)
F1::F2
#If
User avatar
Jadden182
Posts: 21
Joined: 08 Jan 2021, 21:10

Re: PixelGetColor Loop not working

08 Oct 2021, 12:52

Thanks for your help sir. If I pause or suspend this script it continues to work. Do you have any idea as to why?

Code: Select all

#persistent

Numpad0::
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad5::
Numpad6::
Numpad7::
Numpad8::
Numpad9::
0::
1::
2::
3::
4::
5::
6::
7::
8::
9::
User avatar
Jadden182
Posts: 21
Joined: 08 Jan 2021, 21:10

Re: PixelGetColor Loop not working

08 Oct 2021, 13:34

So this is what I've got. It does everything fine except for if it doesn't find the color then it still blocks the keys.


Code: Select all

#persistent




WinWait, % winTitle := "CMS Reporting"
SetTimer, Check, 200
Loop 
{
 WinWaitNotActive
 If WinExist()
  WinActivate
 Else Return
}
Check:
WinGet, WinState, MinMax, %winTitle%
If (WinState = 1) ; Maximized
{
 CoordMode, Pixel, Relative
 PixelGetColor, color, 1002, 791
}
Else WinMaximize, %winTitle%
;Return

if (color ="0x00FF00")
Numpad0::
Numpad1::
Numpad2::
Numpad3::
Numpad4::
Numpad5::
Numpad6::
Numpad7::
Numpad8::
Numpad9::
1::
2::
3::
4::
5::
6::
7::
8::
9::
0::

if (color !="0x00FF00")
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Loop not working

08 Oct 2021, 14:06

You'll want to use the kind of structure that I provided in my example. Yours actually won't work, because you would need a directive to define a context for a hotkey. If is not #If.

Explained: https://www.autohotkey.com/docs/commands/_If.htm
User avatar
Jadden182
Posts: 21
Joined: 08 Jan 2021, 21:10

Re: PixelGetColor Loop not working

14 Oct 2021, 06:26

Okay so this is what I've got so far. What I'm wanting this to do is check one pixel for a color (constantly check) then if the color is found there make f2 =end. That works. But then if the color is not there I want it to check another spot (constantly) and if the color is found there then I want f2=end. I cant seem to understand how to format this. Thanks for any help sir.



Code: Select all

#persistent
SetTitleMatchMode, RegEx



WinWait, % winTitle := "CMS Reporting"
SetTimer, Check, 200
Loop 
{
 WinWaitNotActive
 If WinExist()
  If WinExist("Label") || WinExist("Master")
    WinActivate, CMS Reporting
}
Check:
WinGet, WinState, MinMax, %winTitle%
If (WinState = 1) ; Maximized
{
 CoordMode, Pixel, Screen
 PixelGetColor, color, 1329, 487 ; spot1
}

#If (color = 0x00FF00)
F2::End ; allow numbers

#Else if (color != 0x00FF00)
PixelGetColor, color, 1343, 484 ; spot2
  #If (color = 0x00FF00)
  F2::End ; allow numbers

  #If (color != 0x00FF00) ; block numbers
  1::
  2::
  3::
  4::
  5::
  6::
  7::
  8::
  9::
  0::
  ;Numpad1::
  ;Numpad2::
  ;Numpad3::
  ;Numpad4::
  ;Numpad5::
  ;Numpad6::
  ;Numpad7::
  ;Numpad8::
  ;Numpad9::
  ;Numpad0::

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

Re: PixelGetColor Loop not working  Topic is solved

17 Oct 2021, 14:04

Code: Select all

SetTitleMatchMode, 2
winTitle = CMS Reporting
Gosub, Reset
Loop
{
 WinWaitNotActive, %winTitle%
 If WinExist(winTitle) {
  If WinExist("Label") || WinExist("Master")
   WinActivate, %winTitle%
  Else Sleep, 150
 } Else Gosub, Reset
}
Reset:
SetTimer, Check, Off
WinWait, %winTitle%
SetTimer, Check, 200
Check:
CoordMode, Pixel
WinGet, winState, MinMax, %winTitle%
If (winState < 1) ; 1 = Maximized
 Return
PixelGetColor, color, 1329, 487
If (color != 0x00FF00)
 PixelGetColor, color, 1343, 484
Return

#If (color = 0x00FF00)
F2::End

#If (color != 0x00FF00)
1::
2::
3::
4::
5::
6::
7::
8::
9::
0::Return
#If
User avatar
Jadden182
Posts: 21
Joined: 08 Jan 2021, 21:10

Re: PixelGetColor Loop not working

18 Oct 2021, 09:34

This works perfectly. Thank you so much!
User avatar
Jadden182
Posts: 21
Joined: 08 Jan 2021, 21:10

Re: PixelGetColor Loop not working

22 Oct 2021, 12:22

Hello again. The script seems to have some sort of bug in it. If there is a window behind "CMS Reporting" then when it is maximized and activated again it glitches. If there is nothing behind it then it works fine. I'm thinking this is due to the constant activation of the window maybe? Any thoughts?
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: PixelGetColor Loop not working

22 Oct 2021, 13:08

I do not have a way to answer that. I think you will need to go line by line, one line at a time, to see what is happening with the specific windows in your situation.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer and 261 guests