AutoHotKey - 调整窗口大小

发布于 2024-09-26 16:43:47 字数 152 浏览 3 评论 0原文

目前,我的客厅里有一台连接到等离子的 HTPC,但我遇到了一些图像残留问题。在长时间浏览网页等时,我会遇到这个问题。但是,使用 AutoHotKey 设置脚本以在计时器上自动调整窗口大小似乎应该相对容易。谁能帮助我开始编写脚本来完成这项任务? (也欢迎任何其他想法)

谢谢!

I currently have a HTPC connected to a plasma in my living room, and I've had a few issues with image retention. While browsing the web, etc. for an extended period of time I'll run into the issue. However, it looks like it should be relatively easy to set up a script with AutoHotKey to resize the window automatically on a timer. Could anyone help me get started on a script to accomplish this task? (Also open to any other ideas)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光无声 2024-10-03 16:43:47

我不久前创建了一个脚本来“规范化”窗口,即调整大小、移动并执行其他操作以使窗口符合我的个人喜好。

每当窗口第一次显示时,它就会被标准化。如果关闭并重新打开,则再次正常化。

以下是脚本的功能版本,应满足原始问题的要求。

我使用的版本要复杂得多,因为它具有更多功能,例如,它支持多个显示器并调整窗口大小,同时考虑Windows任务栏的高度。我使用脚本使打开/保存对话框变大(默认情况下它们太小)。我还用它来自动登录一些网站和应用程序。

; This script "normalizes" windows, i.e. resizes, moves, and performs other
; actions to make a window confirm to my personal preference.

SetTitleMatchMode, 2

; Go into an infinite loop
loop
{
    ; Pause so other apps can execute. 250 milliseconds seems to work well.
    Sleep, 250

    ; If hotkeys are suspended for this script, then suspend all functionality
    if A_IsSuspended
        continue

    ; We will build a unique window name using the window title and window handle.
    ; Store each unique name in an array.
    WinGet, HWND, ID, A
    WinGetTitle, WindowTitle, A
    WinGetClass, WindowClass, A

    ; Remember the previous window we processed
    WindowTitleCleanPrevious := WindowTitleClean

    ; Only normalize windows that we haven't seen before.
    ; If we haven't already normalized the window, we do
    ; the normalize, then set a flag so we don't normalize the same window again.

    ; Strip out all chars that may be invalid in an AHK variable name.
    WindowTitleCleanTemp := StringRemoveAllNonAlphaNum(WindowTitle)
    ; Variable names can be at most 254 chars, so truncate to less than that.
    StringLeft, WindowTitleClean, WindowTitleCleanTemp, 230

    ; Process the window if:
    ; (1) It wasn't previously processed (i.e. not in our window-name list named WinList)
    ; (2) And we aren't sitting on the same window during each loop.
    if (WinList%HWND%%WindowTitleClean% != 1 and WindowTitleClean != WindowTitleCleanPrevious)
    {
        ; Get the window's position and size
        WinGetPos, WinX, WinY, WinWidth, WinHeight, A

        ; Is this an MS Word window?
        if (WindowClass == "OpusApp")
        {
            ; Center the window and resize so it is 80% of the monitor width and 90% of height.
            WinMove, A, , (A_ScreenWidth/2)-(WinWidth/2), (A_ScreenHeight/2)-(WinHeight/2), A_ScreenWidth * .8, A_ScreenHeight * .9
        }
        ; Is this the Calculator window?
        else if (WindowClass == "SciCalc")
        {
            ; Center the window
            WinMove, A, , (A_ScreenWidth/2)-(WinWidth/2), (A_ScreenHeight/2)-(WinHeight/2) 
        }

        ; Set a flag indicating this window has been processed so it is
        ; not processed again.
        WinList%HWND%%WindowTitleClean% = 1
    }
}


; --- Win+F5 will Reload this script ---
~#F5::Reload

; --- Win+Escape will Pause this script ---
~#Escape::Suspend, Toggle

; --- Win+Alt+Escape will Exit this script ---
; Close this script
~#!Escape::ExitApp



; ===========================================================================
; Removes all non-alphabetic and non-numeric characters from the given
; string.  The resulting string is returned.
; ===========================================================================
StringRemoveAllNonAlphaNum(SourceString)
{
    StringSplit, SplitSourceString, SourceString

    OutputString =
    Loop, %SplitSourceString0%
    {
        Char := SplitSourceString%A_Index%
        if (Char >= "a") and (Char <= "z")
            OutputString := OutputString Char
        else if (Char >= "0") and (Char <= "9")
            OutputString := OutputString Char
    }

    return OutputString
}

I created a script quite a while ago that "normalizes" windows, i.e. resizes, moves, and performs other actions to make a window confirm to my personal preference.

Whenever a window displays for the first time, it is normalized. If it is closed and re-opened, it is normalized again.

Below is a functioning version of the script and should satisfy the requirements from the original question.

The version I use is much more complicated because it has many more features, e.g. it supports multiple monitors and resizes windows while taking into account the height of the Windows task bar. I use the script to make open/save dialogs bigger (they are too small by default). I also use it to auto-login to some websites and applications.

; This script "normalizes" windows, i.e. resizes, moves, and performs other
; actions to make a window confirm to my personal preference.

SetTitleMatchMode, 2

; Go into an infinite loop
loop
{
    ; Pause so other apps can execute. 250 milliseconds seems to work well.
    Sleep, 250

    ; If hotkeys are suspended for this script, then suspend all functionality
    if A_IsSuspended
        continue

    ; We will build a unique window name using the window title and window handle.
    ; Store each unique name in an array.
    WinGet, HWND, ID, A
    WinGetTitle, WindowTitle, A
    WinGetClass, WindowClass, A

    ; Remember the previous window we processed
    WindowTitleCleanPrevious := WindowTitleClean

    ; Only normalize windows that we haven't seen before.
    ; If we haven't already normalized the window, we do
    ; the normalize, then set a flag so we don't normalize the same window again.

    ; Strip out all chars that may be invalid in an AHK variable name.
    WindowTitleCleanTemp := StringRemoveAllNonAlphaNum(WindowTitle)
    ; Variable names can be at most 254 chars, so truncate to less than that.
    StringLeft, WindowTitleClean, WindowTitleCleanTemp, 230

    ; Process the window if:
    ; (1) It wasn't previously processed (i.e. not in our window-name list named WinList)
    ; (2) And we aren't sitting on the same window during each loop.
    if (WinList%HWND%%WindowTitleClean% != 1 and WindowTitleClean != WindowTitleCleanPrevious)
    {
        ; Get the window's position and size
        WinGetPos, WinX, WinY, WinWidth, WinHeight, A

        ; Is this an MS Word window?
        if (WindowClass == "OpusApp")
        {
            ; Center the window and resize so it is 80% of the monitor width and 90% of height.
            WinMove, A, , (A_ScreenWidth/2)-(WinWidth/2), (A_ScreenHeight/2)-(WinHeight/2), A_ScreenWidth * .8, A_ScreenHeight * .9
        }
        ; Is this the Calculator window?
        else if (WindowClass == "SciCalc")
        {
            ; Center the window
            WinMove, A, , (A_ScreenWidth/2)-(WinWidth/2), (A_ScreenHeight/2)-(WinHeight/2) 
        }

        ; Set a flag indicating this window has been processed so it is
        ; not processed again.
        WinList%HWND%%WindowTitleClean% = 1
    }
}


; --- Win+F5 will Reload this script ---
~#F5::Reload

; --- Win+Escape will Pause this script ---
~#Escape::Suspend, Toggle

; --- Win+Alt+Escape will Exit this script ---
; Close this script
~#!Escape::ExitApp



; ===========================================================================
; Removes all non-alphabetic and non-numeric characters from the given
; string.  The resulting string is returned.
; ===========================================================================
StringRemoveAllNonAlphaNum(SourceString)
{
    StringSplit, SplitSourceString, SourceString

    OutputString =
    Loop, %SplitSourceString0%
    {
        Char := SplitSourceString%A_Index%
        if (Char >= "a") and (Char <= "z")
            OutputString := OutputString Char
        else if (Char >= "0") and (Char <= "9")
            OutputString := OutputString Char
    }

    return OutputString
}
白况 2024-10-03 16:43:47

我正在研究同样的问题。以下脚本可根据您当前的屏幕尺寸打开并居中 Windows 计算器。我仍在弄清楚一切,但这也许会让你开始。

;This script opens and centers the calculator on your screen.
#NoTrayIcon
Run, calc.exe
WinWait, Calculator
WinGetPos,,, Width, Height, %WinTitle%
WinMove, %WinTitle%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
Return

I am working on the same problem. Here is a script that opens and centers the Windows calculator based of your current screen size. I am still figuring everything out, but maybe this will get you started.

;This script opens and centers the calculator on your screen.
#NoTrayIcon
Run, calc.exe
WinWait, Calculator
WinGetPos,,, Width, Height, %WinTitle%
WinMove, %WinTitle%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
Return
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文