AutoHotkey Script for Chrome Full-Screen Toggle Functionality

Answered using GPT-4o Mini by GPT4oMini.app

Question:

#Requires AutoHotkey v2.0 Persistent SetTimer UpdateFullScreenStatus, 1000 ; 初始化变量 toggle global toggle := 0 return

UpdateFullScreenStatus(){ global IsChromeFullScreen IsChromeFullScreen := false

; 判断Chrome是否为当前活动窗口
If WinActive("ahk_class Chrome_WidgetWin_1")
{
    WinGetPos ,, &Width, &Height
    ; 判断窗口是否与屏幕尺寸相同(即全屏)
    IsChromeFullScreen := (Width = A_ScreenWidth && Height = A_ScreenHeight)
}
return

}

#HotIf (WinActive("ahk_class Chrome_WidgetWin_1") && IsChromeFullScreen) XButton1::{ Send "{Left}" KeyWait "XButton1","T1" If GetKeyState("XButton1", "P") Send "{XButton1 up}" return } XButton2::{ Send "{Right}" KeyWait "XButton2","T1" If GetKeyState("XButton2", "P") Send "{XButton2 up}" return } #HotIf ; 重置条件

; 设置热键 Win + Ctrl + Z #^z:: { ; 根据 toggle 的值执行不同的命令 if (toggle = 0) { ; 执行 DisplaySwitch.exe /internal

Answer:

It looks like you're working on an AutoHotkey script that toggles certain functionalities when Google Chrome is in full-screen mode. The script checks if Chrome is the active window and whether it is in full-screen mode, and it sets up hotkeys for mouse buttons XButton1 and XButton2 to send left and right arrow key presses, respectively.

Here's a continuation and completion of your script, including the toggle functionality for the Win + Ctrl + Z hotkey:

        ; 执行 DisplaySwitch.exe /internal
        Run, DisplaySwitch.exe /internal
        toggle := 1  ; 更新 toggle 状态
    } else {
        ; 执行 DisplaySwitch.exe /extend
        Run, DisplaySwitch.exe /extend
        toggle := 0  ; 更新 toggle 状态
    }
    return
}

Explanation of the Script:

  1. Persistent and Timer: The script is set to run persistently and checks every second if Chrome is in full-screen mode.

  2. Global Variable: A global variable toggle is initialized to keep track of the toggle state.

  3. UpdateFullScreenStatus Function: This function checks if the active window is Chrome and whether it is in full-screen mode by comparing its dimensions to the screen size.

  4. Hotkeys:

    • XButton1 sends a left arrow key press when Chrome is in full-screen mode.
    • XButton2 sends a right arrow key press under the same condition.
  5. Toggle Hotkey: The Win + Ctrl + Z hotkey toggles between two commands:

    • If toggle is 0, it runs DisplaySwitch.exe /internal and sets toggle to 1.
    • If toggle is 1, it runs DisplaySwitch.exe /extend and sets toggle to 0.

Additional Notes:

  • Make sure that DisplaySwitch.exe is accessible in your system's PATH or provide the full path to the executable.
  • You can customize the behavior of the hotkeys and the toggle functionality as per your requirements.
  • Ensure that you have AutoHotkey v2.0 installed, as the script is written