need help: script counting wondows

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tocodeornottocode
Posts: 2
Joined: 18 Nov 2015, 11:54

need help: script counting wondows

18 Nov 2015, 11:57

Hi guys,
I want to create a script and am in a desperate need of your help. All I want the script to do is:

1. I start the script
2. i open one ore more window with the special ahk_class
3. script is counting how many of them is running
4. sends a keystroke until i have the desired amount of window with that ahk_class running
5. when i have less than desired, sends thekeystroke again. That way it makes sure i have always 3 windows running
plus option: woud be nice if i coud determine how many windows i want to be opened/closed. after i reach the total amount, script would stop.

This is what I have at this moment:

Code: Select all

#SingleInstance
windowsneeded = 3

Loop
{
    numwindows := 0
    WinGet, id, list, ahk_class ...,, Program Manager
    Loop, %id%
    {
        numwindows += 1
    }
    if (numwindows < windowsneeded)
    {
		sendinput ...
    }
    Sleep 1000
}
return
however this script waits until I have 1 window open and then it sends the keystroke two times.
thanks for your help in advance guys!
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: need help: script counting wondows

18 Nov 2015, 15:08

first: you already have the windows count after you call WinGet in the ID variable, from docs for WinGet
while OutputVar itself is set to the number of retrieved items (0 if none)
second, may be something like that:

Code: Select all

#SingleInstance
windowsneeded = 3
 
Loop
{
    WinGet, numwindows, list, ahk_class ...,, Program Manager ; see WinGet in the help file
	if (numwindows < windowsneeded){ ; that means 2 WINDOWS AT MOST
		Loop, %numwindows%
		{
			ControlSend, ahk_parent, YOUR KEYS HERE, % "ahk_id " numwindows%A_Index% ; read about  ControlSend in the help file
			; I'm not sure where  you want you sleep commmand, after each itteration of the numwindows or the top level loop so...
			; Sleep 1000 ; uncomment this 
		}
	}
	; Sleep 1000 ; or uncomment this
}
return
tocodeornottocode
Posts: 2
Joined: 18 Nov 2015, 11:54

Re: need help: script counting wondows

18 Nov 2015, 15:26

thanks for your input MJs!:)
I will take a look and try the script soon...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, Bing [Bot], peter_ahk and 334 guests