need help to make a array and compare the content to current active window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Sojiro84
Posts: 17
Joined: 02 Feb 2016, 15:49

need help to make a array and compare the content to current active window

06 Feb 2016, 14:01

Allright, to start, here is my script so far;

http://p.ahkscript.org/?p=b09242f0

I have a script to center windows for me. After using it for a while I had to make exceptions for certain windows. Now, I make a new line for every window that should not be affected but this should and probably can, be done more efficiently.

I read the autohotkey help for arrays and did some googling but can't find a good example that I can use in my code. Making a array with the class names is the easy part, but how do I check my current active window to the content of the array and if there is a match, don't center and continue?

I am sure the amount if lines I currently use in my script can be halved.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: need help to make a array and compare the content to current active window

06 Feb 2016, 14:26

Example:

Code: Select all

array:=["Red","Blue","Yellow"]
detectedcolor=green

primary:=false
Loop % array.MaxIndex()
If (detectedcolor=array[A_Index])
    primary:=true
If primary
   MsgBox The color found was primary
else
   MsgBox The color found was not primary



; the array is still defined, so now we just need to change the detectedcolor variable's value
detectedcolor=blue

primary:=false
Loop % array.MaxIndex()
If (detectedcolor=array[A_Index])
    primary:=true
If primary
   MsgBox The color found was primary
else
   MsgBox The color found was not primary
return
An alternative to arrays in this case is to use If var in
Sojiro84
Posts: 17
Joined: 02 Feb 2016, 15:49

Re: need help to make a array and compare the content to current active window

06 Feb 2016, 14:40

Exaskryz wrote:Example:

Code: Select all

array:=["Red","Blue","Yellow"]
detectedcolor=green

primary:=false
Loop % array.MaxIndex()
If (detectedcolor=array[A_Index])
    primary:=true
If primary
   MsgBox The color found was primary
else
   MsgBox The color found was not primary



; the array is still defined, so now we just need to change the detectedcolor variable's value
detectedcolor=blue

primary:=false
Loop % array.MaxIndex()
If (detectedcolor=array[A_Index])
    primary:=true
If primary
   MsgBox The color found was primary
else
   MsgBox The color found was not primary
return
An alternative to arrays in this case is to use If var in

I tried to adept your code to fit with mine and after many tries nothing worked in my script. I ended up with:

Code: Select all

	WinGetClass, Class, A
	
	Array := ["DV2ControlHost", "BaseBar"]
	
	Loop % Array.MaxIndex()
		If (Class == Array[A_Index])
			Continue
What am I doing wrong?
Sojiro84
Posts: 17
Joined: 02 Feb 2016, 15:49

Re: need help to make a array and compare the content to current active window

06 Feb 2016, 14:44

Found it! The link you gave me had the answer:

Code: Select all

	WinGetClass, Class, A
		
	If Class contains DV2ControlHost,BaseBar  
		Continue 
I knew there had to be a short and simple way for my simple script and there it is. Thanks a ton!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk, septrinus and 321 guests