AutoHotkey Script for Chrome Full-Screen Control and Display Toggle

Answered using GPT-4o 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 your script is cut off at the end. I'll help you complete it. The script is designed to check if Google Chrome is in full-screen mode and then remap the XButton1 and XButton2 mouse buttons to send left and right arrow key presses, respectively. Additionally, it includes a hotkey (Win + Ctrl + Z) to toggle between different display settings using DisplaySwitch.exe.

Here's the completed script:

#Requires AutoHotkey v2.0
Persistent
SetTimer UpdateFullScreenStatus, 1000
; Initialize variable toggle
global toggle := 0
return

UpdateFullScreenStatus(){
    global IsChromeFullScreen
    IsChromeFullScreen := false
    
    ; Check if Chrome is the active window
    If WinActive("ahk_class Chrome_WidgetWin_1")
    {
        WinGetPos ,, &Width, &Height
        ; Check if the window size matches the screen size (i.e., full screen)
        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   ; Reset condition

; Set hotkey Win + Ctrl + Z
#^z::
{
    ; Execute different commands based on the value of toggle
    if (toggle = 0) {
        ; Execute DisplaySwitch.exe /internal
        Run "DisplaySwitch.exe /internal"
        toggle := 1
    } else {
        ; Execute DisplaySwitch.exe /extend
        Run "DisplaySwitch.exe /extend"
        toggle := 0
    }
    return
}

Explanation:

  1. Persistent: Keeps the script running.
  2. SetTimer UpdateFullScreenStatus, 1000: Calls the UpdateFullScreenStatus function every second to check if Chrome is in full-screen mode.
  3. UpdateFullScreenStatus(): Checks if Chrome is the active window and if it is in full-screen mode.
  4. #HotIf: Conditional hotkeys that only work when Chrome is in full-screen mode.
  5. XButton1 and XButton2: Remap the mouse buttons to send left and right arrow key presses.
  6. #^z: Toggles between different display settings using DisplaySwitch.exe.

Feel free to adjust the script as needed for your specific use case.