auto pause script when chrome is maximized.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zcw1030
Posts: 34
Joined: 03 Mar 2020, 04:09

auto pause script when chrome is maximized.

Post by zcw1030 » 28 Nov 2022, 01:10

hi, i got some code from others help. it will auto maximize chrome window if it is active.

but, if i click any extension button on top right corner of chrome, the window that popup will also be maximized.

so, is there anyway to fix this issue? for example, pause the script if chrome is already maximized.

thx a lot!

Code: Select all

Loop {
   WinWaitActive, ahk_class Chrome_WidgetWin_1 ahk_exe chrome.exe
   WinMaximize
   WinWaitNotActive
}

bestuser
Posts: 15
Joined: 15 Sep 2022, 07:11

Re: auto pause script when chrome is maximized.

Post by bestuser » 28 Nov 2022, 03:08

Code: Select all

Loop {
    WinGetPos, x, y,,, ahk_exe chrome.exe
    if(x == -8 && y == -8) {
        Pause
    }
    ;Sleep, 25
}
^ should work, but ahk uses a lot of cpu when looping like this, i advise you to put a timer of 25 or 50 ms to reduce cpu usage

bestuser
Posts: 15
Joined: 15 Sep 2022, 07:11

Re: auto pause script when chrome is maximized.

Post by bestuser » 28 Nov 2022, 03:18

sorry, forgot to include this in last reply

Code: Select all

Loop {
    GetKeyState, MBCS, LButton, P
    WinGetPos, x, y,,, ahk_exe chrome.exe
    if(MBCS != "D" && x == -8 && y == -8) {
        Pause
    }
}
[Mod edit: [code][/code] tags added.]

since who knows, maybe you are hovering your app around. this will detect if you have your mousebutton down to prevent false-detection
still advise you to use a delay to avoid high cpu

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

Re: auto pause script when chrome is maximized.

Post by mikeyww » 28 Nov 2022, 04:23

Code: Select all

#SingleInstance Force
wTitle = ahk_class Chrome_WidgetWin_1 ahk_exe chrome.exe
Loop {
 WinWaitActive, %wTitle%
 WinMaximize
 SoundBeep, 1500
 WinWaitNotActive, %wTitle%
 SoundBeep, 1000
}


zcw1030
Posts: 34
Joined: 03 Mar 2020, 04:09

Re: auto pause script when chrome is maximized.

Post by zcw1030 » 28 Nov 2022, 06:21

bestuser wrote:
28 Nov 2022, 03:18
sorry, forgot to include this in last reply

Code: Select all

Loop {
    GetKeyState, MBCS, LButton, P
    WinGetPos, x, y,,, ahk_exe chrome.exe
    if(MBCS != "D" && x == -8 && y == -8) {
        Pause
    }
}
[Mod edit: [code][/code] tags added.]

since who knows, maybe you are hovering your app around. this will detect if you have your mousebutton down to prevent false-detection
still advise you to use a delay to avoid high cpu
sry, can you post a comeplete script, since the scripts in your two posts not working.
thx!

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

Re: auto pause script when chrome is maximized.

Post by mikeyww » 28 Nov 2022, 06:36

Mine worked when I tested it.

Post Reply

Return to “Ask for Help (v1)”