Help with v2 script to toggle between fullscreen and windowed modes Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Unknown123
Posts: 3
Joined: 18 Nov 2023, 12:43

Help with v2 script to toggle between fullscreen and windowed modes

19 Nov 2023, 11:24

Hello, I was helped with converting a script from v1 to v2 earlier, but it's still not fully functional yet. Could someone help me to get it working please, as I'm not experienced with AHK.
It's supposed to toggle between fullscreen and windowed modes of an application when pressing F12, as well as hide the taskbar during the fullscreen mode. I need it to work with a multi-monitor setup. What happens right now is, it just toggles a white border around the active application when I press F12, and It also only has any sort of effect on my main screen. When I try it on an application on my second monitor, the active window disappears from view completely on the second monitor, and the taskbar disappears on the first monitor. Any help would be very appreciated, and thank you in advance.

Code: Select all

#Requires AutoHotkey v2.0

; Toggle between fullscreen and windowed modes when pressing F12 as well as hide the taskbar during the fullscreen mode

F12::{
  static windowId := "", winPosX, winPosY, windowWidth, windowHeight, windowState := ""
  tempWindowId := WinExist("A")
  
  if (windowId != tempWindowId) {
    windowId := tempWindowId
    windowState := 0
  }
  
  if (windowState != 1) {
    WinGetPos &winPosX, &winPosY, &windowWidth, &windowHeight, windowId
    WinSetStyle "-0xC40000", windowId
    WinMove 0, 0, A_ScreenWidth, A_ScreenHeight, windowId
    ;Hide Windows Task Bar and Start Button. (Remove the following two lines if you don't want that behaviour)
    try WinHide "ahk_class Shell_TrayWnd"
    try WinHide "Start ahk_class Button"
  } else {
    WinSetStyle "+0xC40000", windowId
    WinMove winPosX, winPosY, windowWidth, windowHeight, windowId
    ;Show the task bar again
    try WinShow "ahk_class Shell_TrayWnd"
    try WinShow "Start ahk_class Button"
  }
  windowState := !windowState
}
Unknown123
Posts: 3
Joined: 18 Nov 2023, 12:43

Re: Help with v2 script to toggle between fullscreen and windowed modes

19 Nov 2023, 14:37

Incase it's helpful to know, this was the original v1 script before someone helped convert it to the v2 script I posted.

Code: Select all

#UseHook On
F12::
WinGet, TempWindowID, ID,  
If (WindowID != TempWindowID)
{
  WindowID:=TempWindowID
  WindowState:=0
}
If (WindowState != 1)
{
  WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
  WinSet, Style, -0xC40000, ahk_id %WindowID%
  WinMove, ahk_id %WindowID%, , 0, 0, A_ScreenWidth, A_ScreenHeight
  ;Hide Windows Task Bar and Start Button. (Remove the following two lines if you don't want that behaviour)
  WinHide ahk_class Shell_TrayWnd
  WinHide Start ahk_class Button
}
Else
{
  WinSet, Style, +0xC40000, ahk_id %WindowID%
  WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
  ;Show the task bar again
  WinShow ahk_class Shell_TrayWnd
  WinShow Start ahk_class Button
}
WindowState:=!WindowState
return
Unknown123
Posts: 3
Joined: 18 Nov 2023, 12:43

Re: Help with v2 script to toggle between fullscreen and windowed modes  Topic is solved

20 Nov 2023, 17:30

Since I'm not experienced with AHK, it took me a little while to figure out that the numbers that decide where the active window is moved to when toggling the script, can also go into the minus. So to get the script to move the active window to my other monitor instead of completely off-screen, I just needed to change the line from:

Code: Select all

WinMove 0, 0, A_ScreenWidth, A_ScreenHeight, windowId
to

Code: Select all

WinMove -1920, 0, A_ScreenWidth, A_ScreenHeight, windowId
plaguedoc
Posts: 1
Joined: 12 May 2024, 05:10

Re: Help with v2 script to toggle between fullscreen and windowed modes

12 May 2024, 05:11

Your code works great for my purposes. Thanks for posting!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken, hiahkforum, WarlordAkamu67, zabbn and 29 guests