AutoHotkey:使用快捷鍵,在雙顯示器間,移動最大化的窗口

無意間看了我以前寫的一篇博客:VC++: 在雙顯示器間,移動最大化的窗口

當時我想解決的問題是這樣的:

無需通過多步鼠標操作, 使用快捷鍵, 直接將我想移動的窗口, 移動到我希望的顯示器上(我期望的位置.)

包括移動最大化窗口(xp中,最大化窗口是需要先還原才能再移動的)

 

當時的解決辦法是寫了一個c++程序(命令行程序,無窗口), 負責在多顯示器之間移動窗口.

然後在用AutoHotkey爲這個命令行程序配一個快捷鍵.

 

時隔多年回頭一看, 發現我已經對這個問題有了新的認識.

隨着對AutoHotkey的認識的加深,

如果現在讓我做這個問題, 我已經不再會寫一個C++程序.

而會直接用AutoHotkey實現全部的功能.

 

方式可以詳參下面這幾個連接, 他們使用的都是AutoHotkey:

Keyboard shortcut for moving a window to another screen@superuser

WindowPad - window-moving tool@AutoHotkey Community

WindowPadX@github

 

第一個連接上面有下面兩份代碼可供參考.

 

#q::
WinGetPos, winx, winy,,, A
WinGet, mm, MinMax, A
WinRestore, A
If (winx > 1270)
{
    newx := winx-1270
    OutputDebug, Moving left from %winx% to %newx%
}
else
{
    newx := winx+1270
    OutputDebug, Moving right from %winx% to %newx%
}

WinMove, A,, newx, winy

if mm=1
    WinMaximize, A
Return

 

 

#z:: ;Move the active window to the other monitor.
WinGetPos, winx, winy,,, A
WinGet, oldWin,ID,A
WinActivate, A
WinGet, mm, MinMax, A
WinRestore, A
If winx+5 >= 0 then
    mult=1
else
    mult=-1
WinMove,A,, winx-(1680*mult), winy
if mm=1
    WinMaximize, A
Return
 

第二個連接WindowPad ,關於移動窗口, 提供了更多的功能,

有腳本,也有編譯好的exe,下載下來直接運行使用,很方便,

我們想要的功能(跨顯示器移動窗口)對應的快捷鍵是: Win+小鍵盤上面的回車

他的功能包括:

寫道
■Move windows within the current monitor or between monitors (in multi-monitor setups).
■Customize hotkeys via WindowPad.ini with AutoHotkey-like command syntax.
■Define custom commands as labels or functions in WindowPad.ahk.
■Execute WindowPad commands specified on the command-line.
 

第三個連接WindowPadX 是第二個連接(WindowPad )的一個增強.

他們都有Source, 可以隨時參考.

 

 

最後, 這個功能已經內置在Windows 7之中.

所以, win7用戶有了福, 如果你是win7用戶, 直接按下下面這兩組快捷鍵吧:

寫道
Win+Shift+left: Move focussed window one monitor to the left
Win+Shift+right: Move focussed window one monitor to the right
  

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章