If win not active > pause all scripts

Get help with using AutoHotkey and its commands and hotkeys
Bender646
Posts: 1
Joined: 08 Jun 2019, 12:17

If win not active > pause all scripts

08 Jun 2019, 12:38

Hello, can you pls help me how can i pause all my scripts and they shortcuts if window is not active ? I set loop 1s to check if win active, then go to label, but problem is how to pause or resume script.
I use this code, to pause it manualy, but it is toggle.
Simple :
- if win si not active - all scripts are paused
- if i go back to window all scripts resume


Code: Select all

F3::


DetectHiddenWindows, On 

WinGet, IDList ,List, ahk_class AutoHotkey

Loop %IDList%

  {

  ID:=IDList%A_Index%

  WinGetTitle, ATitle, ahk_id %ID%

  IfNotInString, ATitle, %A_ScriptName%

    {

    PostMessage, 0x111, 65305,,, %ATitle%  ; Suspend.

    PostMessage, 0x111, 65306,,, %ATitle%  ; Pause.

    }

  }

Return
User avatar
YoucefHam
Posts: 344
Joined: 24 Aug 2015, 12:56
Facebook: https://fb.me/YoucefHamDz
Google: [email protected]
GitHub: YoucefHam
Location: Algeria
Contact:

Re: If win not active > pause all scripts

09 Jun 2019, 16:52

follow this example

0.ahk

Code: Select all

OnExit("OnExitFunction")
IniWrite, 0, Setting.ini, Settings, Exit
IniWrite, 0, Setting.ini, Settings, IsActive

F3::
IsActive := 1
IniWrite, %IsActive%, Setting.ini, Settings, IsActive
Run, 1.ahk
Run, 2.ahk
return

F4::
IsActive := !IsActive
IniWrite, %IsActive%, Setting.ini, Settings, IsActive
return

F5::
OnExitFunction()
return

OnExitFunction()
{
    IniWrite, 1, Setting.ini, Settings, Exit
    IniWrite, 0, Setting.ini, Settings, IsActive
    ExitApp
    return
}

1.ahk

Code: Select all

i := 0
Loop
{
if !IniRead("Setting.ini", "Settings", "IsActive")
    Loop
    {
        if IniRead("Setting.ini", "Settings", "IsActive")
            break
        if IniRead("Setting.ini", "Settings", "Exit")
            ExitApp
        Sleep, 1000
    }
if IniRead("Setting.ini", "Settings", "Exit")
    ExitApp
ToolTip, % i++, 0, 0, 1
}



;  Function
IniRead(File, Section, key)
{
    IniRead, var, % File, % Section, % key
    return, var
}


2.ahk

Code: Select all

i := 0
Loop
{
if !IniRead("Setting.ini", "Settings", "IsActive")
    Loop
    {
        if IniRead("Setting.ini", "Settings", "IsActive")
            break
        Sleep, 1000
        if IniRead("Setting.ini", "Settings", "Exit")
            ExitApp
    }
if IniRead("Setting.ini", "Settings", "Exit")
    ExitApp
ToolTip, % i++, 0, 50, 2
}



;  Function
IniRead(File, Section, key)
{
    IniRead, var, % File, % Section, % key
    return, var
}

:wave: There is always more than one way to solve a problem. ;)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bibliocrat, Google [Bot], JoeWinograd, mikeyww, nutnutwin, TAC109 and 53 guests