tatsu
tatsu

Reputation: 2536

AutoHotkey script for automatic windowed-fullscreen on a specific app

Here's where I'm at :

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 3

Loop { ; apparently a loop is recommended for app-as-a-trigger.

  Send, ^!a



WinGet, p_exe, ProcessName, Forged Alliance, Style, Style, A {
if(Style & 0xC40000) {
  WinSet, Style, -0xC40000, A
  WinMaximize, A 

}
Sleep, 100
}
}
return

Obviously i'm trying to make it so that when ForgedAlliance.exe runs it's window borders are removed and it is maximised.

i had a working script triggered by a hotkey :

LWin & f::

WinGet Style, Style, A
if(Style & 0xC40000) {
  WinSet, Style, -0xC40000, A
  WinMaximize, A 

} else {
  WinSet, Style, +0xC40000, A
  WinRestore, A
}
return

and now I wish for it to be triggered by the App running.

I tried :

If ProcessExist("ForgedAlliance.exe") {

}
return

but that did not work, this condition always returned true (always executed the code) even though FA was not running at targeted anything my mouse hovered.

What is the correct way to go about this?

Upvotes: 0

Views: 2233

Answers (2)

Elliot DeNolf
Elliot DeNolf

Reputation: 2999

From your description, it sounds like you're putting your loop inside of your process check. Which means it will only check for that once. Here is a better solution that uses a timer.

#Persistent

procName := "ForgedAlliance.exe"
SetTimer, CheckProc, 2000
Return

CheckProc:
    If (!ProcessExist(procName))
        Return

    WinGet Style, Style, % "ahk_exe " procName
    If (Style & 0xC40000) 
    {
        WinSet, Style, -0xC40000, % "ahk_exe " procName
        WinMaximize, % "ahk_exe " procName
    }
    Return

ProcessExist(exeName)
{
   Process, Exist, %exeName%
   return !!ERRORLEVEL
}

Upvotes: 1

fischgeek
fischgeek

Reputation: 688

Your Process Exist check needs to go inside a timer.

#Persistent
SetTimer, CheckForProcess, 100

CheckForProcess:
{
    Process, Exist, ForgedAlliance.exe
    if (ErrorLevel) {
        ; process is running
    }
    return
}

Upvotes: 1

Related Questions