AutoHotkey - Script to Toggle Minimize/Maximize Window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 00:08

I simply wish to be able to toggle with a hotkey Minimize & Maximize on ONE certain full screen app that I always use.
I want to use this for only one app, and not whichever app has focus.

I know there are a few commands that I could use:

Code: Select all

WinMinimize, A
WinMaximize, A
But I am not sure how to string it all together. When looking for examples I came up with this somewhere:

Code: Select all

^#n::
IfWinExist, ahk_class Notepad
{
WinGet,WinState,MinMax,ahk_class Notepad
If WinState = -1
   WinMaximize
else
   WinMinimize
}
; else
;   Run, Notepad
Return
However this only maximized my app, and not minimized it. Perhaps this was due to the fact app was a fullscreen app, i dont know.
I have read dozens of ways to do this online, none of which have worked
Last edited by Bluerose555 on 21 Mar 2017, 15:08, edited 1 time in total.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 08:46

Bluerose555 wrote: none of which have worked
Where are script you've written? that way it will be possible for to detect what exactly was wrong highlighting errors in this scripts and hence help you.
my scripts
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 15:09

A_AhkUser wrote:
Bluerose555 wrote: none of which have worked
Where are script you've written? that way it will be possible for to detect what exactly was wrong highlighting errors in this scripts and hence help you.
Added new information to original post.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 17:09

which values display this msgbox when your trigger this hotkey in full screen mode?

Code: Select all

^#n::
WinGetPos, X, Y, Width, Height, PUT_YOUR_WINTITLE_HERE
MsgBox % X . "," . Y . "," . Width . "," . Height
return
EDIT: because I try it out with VLC

maximized:
---------------------------
__ahk.ahk
---------------------------
0,0,1366,768
---------------------------
OK
---------------------------

full screen:
---------------------------
__ahk.ahk
---------------------------
-8,-8,1382,754
---------------------------
OK
---------------------------

minimized:
---------------------------
__ahk.ahk
---------------------------
-32000,-32000,160,28
---------------------------
OK
---------------------------


so maybe you can make an ifstatement monitoring code depending on window positions (only X is necesary here to distinguish between three mode: 0 maximized ; -8 fullscreen ;-32000 minimized)?
Last edited by A_AhkUser on 21 Mar 2017, 21:20, edited 1 time in total.
my scripts
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 18:52

A_AhkUser wrote:which values display this msgbox when your trigger this hotkey in full screen mode?

so maybe you can make an ifstatement monitoring code depending on window positions (only X is necessary here to distinguish between three mode: 0 maximized ; -8 fullscreen ;-32000 minimized)?
Here are the values that came from that script:

minimized = -32000,-32000,160,37
in full screen mode = 0,0,1920,1080

I do not know about 'if' commands or how to build a script.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 19:18

Bluerose555 wrote:in full screen mode = 0,0,1920,1080
it's seems your screen is a way more wide than mine...
Bluerose555 wrote:I do not know about 'if' commands.
see: https://www.autohotkey.com/docs/command ... ession.htm
also: https://www.autohotkey.com/docs/commands/Block.htm

here's a template:

Code: Select all

var := "Ceci est un test."
if (var == "Ceci est un test.")
{
MsgBox, var contents the sentence: Ceci est un test
} 
else
{
MsgBox, this msgbox will never be displayed.
}
Bluerose555 wrote:or how to build a script.
it is another question.



EDIT:
here's an other exemple to illustrate and help you start:

Code: Select all

run % A_WinDir . "/notepad.exe" ; run notepad
sleep, 1000 ; waits 1 seconds
WinMinimize, ahk_class Notepad
WinGetPos, X, Y, Width, Height, ahk_class Notepad
if (X == -32000)
MsgBox, Notepad is minimized
WinMaximize, ahk_class Notepad
WinGetPos, X, Y, Width, Height, ahk_class Notepad
if (X == 0 and Y == 0 and Width == 1920 and Height == 1080)
MsgBox, Notepad is maximized
return
my scripts
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 19:32

thank you for your replies. I don't want to launch the program though. The program will already be launched. I simply need a script to minimize it from full screen, and maximize it to full screen with the press of ONE button (same button for bot actions) =)

Also in the script above I dont see anything that binds a key to anything.
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 20:15

why doesnt this work ? is it because the spaces are wrong?
Joy12::

WinRestore, Resident Evil 4

return
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 20:23

Bluerose555 wrote:thank you for your replies. I don't want to launch the program though. The program will already be launched.
That's fine but if my script doesn't start notepad on which window it will operate to illustrate how it works? :?:
Also in the script above I dont see anything that binds a key to anything.
That's why I called it template. The first code you've posted does define a hotkey that trigger a subroutine. and here it's one of two things:
you don't really understand how the code you posted works basically - and in this case you should ask for it before in the start of the thread -- either you understand enogh so it will be possible for you try make your own starting from the template and knocking up the material here and posting a code with an answer like you do at the begining saying that your code only maximized my app, and not minimized it.
my scripts
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 20:26

Bluerose555 wrote:why doesnt this work ? is it because the spaces are wrong?
Joy12::

WinRestore, Resident Evil 4

return
Here an answer based on attempt you've done!
my scripts
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 20:30

A_AhkUser wrote:
Bluerose555 wrote:why doesnt this work ? is it because the spaces are wrong?
Joy12::

WinRestore, Resident Evil 4

return
Here an answer based on attempt you've done!
ok so what now? Is this a complicated issue? It seems that there are dozens of functions that are supposed to make this easy, but i have been writing here on this message board for over 24 hours just trying to get a simple answer.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 20:30

maybe the title...
did you try to run AU3_Spy.exe in tha autohotkey install directory it allows detect title of window
and, in particular class which are more rekliable than simple title

as I seen a joy trigger the subroutine - have you try the joystick test script? (https://autohotkey.com/docs/scripts/JoystickTest.htm)
is joy12 the joypad button you thinked?
my scripts
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 20:40

the joystick works fine in other AHK scripts. I know what the title of the window is. Its "Resident Evil 4" it worked fine in another script. So the issue isnt window title or the Window title, but the command.
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 20:42

could you please provide a script that lets me use Joy12 to toggle Minimize & Maximize for Resident Evil 4?

thank you
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

21 Mar 2017, 20:50

the only issue I think is that as you can see it is written at the top of the page: AUTOHOTKEY Automation Hotkeys Scripting
and you probably read AUTOHOTKEY Automation Hotkeys

anyway no matter

try this:

Code: Select all

Joy12::
WinGetPos, X, Y, Width, Height, Resident Evil 4
if (X == -32000)
WinMaximize, Resident Evil 4
else if (X == 0 and Y == 0 and Width == 1920 and Height == 1080)
WinMinimize, Resident Evil 4
return
don't hesitate ask if it doesn't work and can't figure it out

P.S. Resident Evil 4 is a really good game ;)
my scripts
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

09 May 2020, 01:47

I needed to fix this again after installing WIndows 10. It seems that the focus was getting lost when coming back to WIndows from the game. The game windows minimizes, but all mouse input was still going to the game because the focus was still on the game.

I fixed this by adding:

Code: Select all

WinActivate, Explorer
So the latest version would be:

Code: Select all

Joy12::
WinGetPos, X, Y, Width, Height, Resident Evil 4
if (X == -32000)
WinMaximize, Resident Evil 4
else if (X == 0 and Y == 0 and Width == 1920 and Height == 1080)
WinMinimize, Resident Evil 4
WinActivate, Explorer
return
Thanks!
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

11 Sep 2020, 01:18

I need help again with this last script;

Code: Select all

2Joy12::
WinGetPos, X, Y, Width, Height, Resident Evil 4
if (X == -32000)
WinMaximize, Resident Evil 4
else if (X == 0 and Y == 0 and Width == 1920 and Height == 1080)
WinMinimize, Resident Evil 4
WinActivate, Explorer
return
the WinActivate, Explorer no longer works. While the program does minimize the game, it seems that the focus is lost somewhere with the game still taking input form the keyboard forcing me to ALT Tab out to get focus again on the desktop.

To fix this I did:
2Joy12::
WinGetPos, X, Y, Width, Height, Resident Evil 4
if (X == -32000)
WinMaximize, Resident Evil 4
else if (X == 0 and Y == 0 and Width == 1920 and Height == 1080)
WinMinimize, Resident Evil 4
send {alt}{tab}
return
Bluerose555
Posts: 112
Joined: 20 Mar 2017, 03:02

Re: AutoHotkey - Script to Toggle Minimize/Maximize Window

12 Dec 2020, 05:42

A_AhkUser wrote:
21 Mar 2017, 20:50
don't hesitate ask if it doesn't work and can't figure it out
Hi again! I am trying to set this up for another game I am playing btu its not working and wondering if you can chime in ?
I have created a new post for this topic at the link below:

https://www.autohotkey.com/boards/viewtopic.php?f=18&t=84347&p=369864#p369864

Cheers

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Fredrik F, maxkill, RandomBoy, ShatterCoder and 338 guests