Help using WinWaitActive.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kunkel321
Posts: 1035
Joined: 30 Nov 2015, 21:19

Help using WinWaitActive.

02 May 2019, 13:53

Hi Folks,
I have a main script with a bunch of tools (based on the excellent AutoCorrect.ahk) that runs all the time. I'd like add a thing that will constantly watch for a particular window, then resize the window when it appears. Part of my question is whether WinWaitActive can be used this way. The help docs indicate that #WinWaitActive can NOT be used that way, but it doesn't indicate this with WinWaitActive.

The other part of my question, is how do I use the command to start with!? I wanted to try it in a simple stand-alone script before putting it in my other big script, so I made this:

Code: Select all

#NoEnv ; For security
#SingleInstance force
#Persistent

WinWaitActive, , Web Student Management, 2
MsgBox, Web Window open
The window I'm waiting for changes, but the window title always starts with "Web Student Management."
I tried
WinWaitActive, Web Student Management, , 2
and I tried
WinWaitActive, , Web Student Management, 2

But with both of them, the MsgBox just pops up as soon as I start the script. It does not wait for the window.

Ideas what I'm doing wrong?
Also, Am I even using WinWaitActive correctly?
ste(phen|ve) kunkel
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Help using WinWaitActive.

02 May 2019, 23:04

You can do it by using WinWaitActive inside of a loop, like so:

Code: Select all

Loop
{
    WinWaitActive, Web Student Management
    WinMaximize
    WinWaitNotActive
}
If you don't want to maximize it, then replace that line with a WinMove command.

If you want it to happen only once, when the application is first launched, see the code that I recently whipped up for someone else:
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=64201&p=275306#p275187
Last edited by Osprey on 03 May 2019, 16:32, edited 1 time in total.
User avatar
kunkel321
Posts: 1035
Joined: 30 Nov 2015, 21:19

Re: Help using WinWaitActive.

03 May 2019, 10:34

Thanks for the reply Osprey!

I only need it to maximize the window once, each time the app is launched. For now I'm just trying your above code though--because it's simpler than the one from your March post. I'm not sure it's working though... The window does not maximize. Here's a screenshot, so you don't think I'm crazy:
Image
The script was running before I launched Skyward.

Eh... As I type this, I'm trying the WinSpy ahk tool. If I select the window, WinSpy does not seem to detect the window title(?) Though it does with other windows... I'll paste some of the WinSpy data at the bottom. Note that 'Text: ' is blank.

First though, an additional question: Is it okay to have a loop like this always running in the background with my AutoCorrect script? It doesn't put a strain on system resources?


[General]
Handle: 0xF099E
Text:
Class: Intermediate D3D Window
ClassNN: Intermediate D3D Window1
Style: 0x58000000
Extended: 0x00280024
Position: 0, 0
Size: 1017 x 756
Cursor: 1026, 58

[Details]
Class name Intermediate D3D Window
Control ID 0x0
Font System default
Window procedure -0x48D6BFD9
Instance handle -0x4B7B0000
Class style 0x20 (CS_OWNDC)
Icon handle 0x0
Small icon handle 0x0
Cursor handle 0x0
Background Brush 0x900010
Menu name 0x0
Window extra bytes 0x0
Class extra bytes 0x0
Class atom 0xC4A2
User data 0x0
Unicode Yes
Tab order index 0
Help context ID 0
Touch-capable 0

[Sibling]
0x00140856 Chrome_RenderWidgetHostHWND Chrome Legacy Window

Parent: 0x000C036A (Chrome_WidgetWin_1)
Owner: 0x00000000
ste(phen|ve) kunkel
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Help using WinWaitActive.

03 May 2019, 16:41

Try:

Code: Select all

Loop
{
    WinWaitActive, ahk_class Intermediate D3D Window
    WinMaximize
    WinWaitNotActive
}
If that works, then try this modification of the other script, to make it maximize only on launch:

Code: Select all

#SingleInstance Force

ProcessArray := []
Loop
{
    WinWaitActive, ahk_class Intermediate D3D Window 			; Wait for the application to open
    WinGet, ProcessID, PID										; Get the process ID (PID) of the application's window
    If(!ProcessArray[ProcessID])								; If the window isn't recognized in the array
    {
        WinActivate
        WinMaximize
        ProcessArray[ProcessID] := true							; Add the window's PID to the array
    }
    WinWaitNotActive											; Wait until the window is no longer active
    For index, value in ProcessArray							; Loop through the array
      If(!WinExist("ahk_pid " index))							; If any recognized window no longer exists
          ProcessArray.Delete(index)							; Delete the window's PID from the array
}
To answer your question about undue stress on the system, I don't think that it will, but I did think about that, which is why I added the WinWaitNotActive line, so that the loop never runs out of control. Check the CPU usage while it's running to see if I'm right or not. If it consumes too much CPU, you could always add a Sleep command to the loop, the larger the better for reducing CPU usage, but at the expense of the window maximizing not being quite as instantaneous.
Last edited by Osprey on 03 May 2019, 22:27, edited 1 time in total.
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: Help using WinWaitActive.

03 May 2019, 17:05

According to the screenshot,you are not using the code from the post above your post.
That "2" means that the script will wait 2 seconds for the window to be active and then execute the rest of the code.

Remove the waiting time and also search to a window with that title(according to the screenshot,you are waiting for a window with that text not that title)

This should be working

Code: Select all

Loop
{
    WinWaitActive,Web Student Management
    WinMaximize
    WinWaitNotActive
}
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Help using WinWaitActive.

03 May 2019, 19:04

vsub, what he's using in the screenshot is what I originally posted, since I assumed that he had the syntax right and just copied the line that he had. When I noticed the mistake a couple of hours ago, I edited my post to correct it (just in case he were to refer back to it or someone else were to try to use it).
User avatar
kunkel321
Posts: 1035
Joined: 30 Nov 2015, 21:19

Re: Help using WinWaitActive.

03 May 2019, 21:31

Thanks for the feedback folks. I did have a syntax error! I copied that sample from the bottom of here: https://autohotkey.com/docs/commands/WinWaitActive.htm but I see now that I pasted the winTitle where the winText should have gone. I guess that might also be why my msgBox kept poping right up... Because the test "Web Student Management" was right there in my SciTE4Ahk window(?)

Anyway... I tried it the way you guys have it now and it works. I will also try the longer version, so it won't keep maximizing over and over when I go back to the (already opened) window. Thanks again everyone! :D I will report back on whether there is a processor effect regarding the continuous loop.
ste(phen|ve) kunkel

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, hiahkforum, jchestnut, mcd, ShatterCoder and 99 guests