需要 Autohotkey 将活动窗口居中

Car*_*los 7 autohotkey

我正在寻找一种使用 Autohotkyes 使桌面上的活动窗口居中的方法。有人可以给我一个我可以使用的脚本吗?谢谢

Dir*_*ble 8

这些答案使用标题匹配,可以应用于多个窗口。当您按 win+c 时,这只会使活动窗口居中。

#c::
WinExist("A")
WinGetPos,,, sizeX, sizeY
WinMove, (A_ScreenWidth/2)-(sizeX/2), (A_ScreenHeight/2)-(sizeY/2)
return
Run Code Online (Sandbox Code Playgroud)


Joh*_*esM 6

http://www.autohotkey.com/docs/commands/WinMove.htm是谷歌上第一个带有“autohotkey center window”的结果。它可能会帮助你。请参阅示例脚本。

示例脚本

运行,calc.exe
WinWait,计算器
WinMove, 0, 0 ; 将 WinWait 找到的窗口移动到屏幕的左上角。

SplashTextOn, 400, 300, Clipboard, 剪贴板包含:`n%clipboard%
WinMove, 剪贴板, , 0, 0 ; 将启动窗口移动到左上角。
Msgbox,按 OK 关闭 SplashText
SplashTextOff

; 以下函数使指定窗口在屏幕上居中:
中心窗口(WinTitle)
{
    WinGetPos,,, 宽度,高度,%WinTitle%
    WinMove, %WinTitle%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
}

定制

; 以下函数使指定窗口在屏幕上居中:
中心窗口(WinTitle)
{
    WinGetPos,,, 宽度,高度,%WinTitle%
    WinMove, %WinTitle%,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
    ;Msgbox,使记事本中心?
}

运行,文件.exe

CenterWindow("文件名.exe")

  • 不鼓励仅链接答案,但可以随意应用该链接中的信息,以便答案在您的答案中。 (4认同)

小智 6

为了简单性和适应性,我创建了一个额外的超短脚本,它只获取活动窗口并将其居中,但也根据给定的宽度和高度调整其大小。除了晚了几年之外,这可能不是您真正要求的。但是,这是我对 FHD 以上分辨率时代操作系统的窗口管理的期望。希望其他人也需要它。高频

\n\n
; HOTKEYS\n#!Up::CenterActiveWindow() ; if win+alt+\xe2\x86\x91 is pressed\n\nCenterActiveWindow()\n{\n    windowWidth := A_ScreenWidth * 0.7 ; desired width\n    windowHeight := A_ScreenHeight ; desired height\n    WinGetTitle, windowName, A\n    WinMove, %windowName%, , A_ScreenWidth/2-(windowWidth/2), 0, windowWidth, windowHeight\n}\n
Run Code Online (Sandbox Code Playgroud)\n