AutoHotKey - 调整Windows大小

时间:2010-10-08 18:19:55

标签: resize autohotkey

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

谢谢!

4 个答案:

答案 0 :(得分:5)

我不久前创建了一个脚本,用于“规范化”窗口,即调整大小,移动,并执行其他操作以使窗口按照我个人的喜好进行确认。

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

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

我使用的版本要复杂得多,因为它有更多功能,例如它支持多个监视器并调整窗口大小,同时考虑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
}

答案 1 :(得分:2)

我正在研究同样的问题。这是一个根据您当前屏幕大小打开并centers 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

答案 2 :(得分:0)

您可以使用以下快捷方式调整窗口大小并对齐窗口。您可以使用脚本来运行这些命令。

Windows键+左箭头=窗口捕捉到屏幕的左侧

Windows键+右箭头=窗口捕捉到屏幕的右侧

Windows键+向上箭头=窗口捕捉到屏幕上方

Windows键+向下箭头=窗口捕捉到屏幕下方

Windows键+向上和向左箭头=窗口捕捉到屏幕的左上角

Windows键+向上和向右箭头=窗口捕捉到屏幕的右上角

答案 3 :(得分:0)

您可以使用以下快捷方式调整窗口大小和对齐窗口。

  • Windows键+向左箭头 =窗口捕捉到屏幕左侧
  • Windows键+右箭头 =窗口捕捉到屏幕右侧
  • Windows键+向上箭头 =窗口捕捉到屏幕上方
  • Windows键+向下箭头 =窗口捕捉到屏幕下方
  • Windows键+向上和向左箭头 =窗口捕捉到屏幕的左上角
  • Windows键+向上和向右箭头 =窗口捕捉到屏幕的右上角