您的位置:首页 > 运维架构 > Shell

AHK 快餐店[11] 之 虚拟桌面 AutoHotkey 版

2010-10-19 15:52 127 查看
 

文章标签: AHK / 桌面工具 / 虚拟.

上回我们把键盘折腾个半死,今天我们要折腾的是:桌面。

虚拟桌面有什么用捏?如果你想在上班的时候看小众煎蛋玩游戏……又怕 boss 走过来的时候,手忙脚乱地关闭一堆窗口,那么虚拟桌面是必备的啦。

小众介绍过三款虚拟桌面:Yod’m 3D – 3D 虚拟桌面VirtuaWin – 很酷的虚拟桌面[更新]VirtuaWin – 很酷的虚拟桌面[更新]

废话少说。下载虚拟桌面 AHK 版 | 来源
;虚拟桌面 - Ahk
;Autohotkey的脚本,实现虚拟桌面的功能,快捷键Alt+1,2,3,4
SetBatchLines, -1 ; maximize script speed!
SetWinDelay, -1
OnExit, CleanUp ; clean up in case of error (otherwise some windows will get lost)
numDesktops := 4 ; maximum number of desktops
curDesktop := 1 ; index number of current desktop
WinGet, windows1, List ; get list of all currently visible windows
; ***** hotkeys *****
!1::SwitchToDesktop(1)
!2::SwitchToDesktop(2)
!3::SwitchToDesktop(3)
!4::SwitchToDesktop(4)
^!1::SendActiveToDesktop(1)
^!2::SendActiveToDesktop(2)
^!3::SendActiveToDesktop(3)
^!4::SendActiveToDesktop(4)
!0::ExitApp
; ***** functions *****
; switch to the desktop with the given index number
SwitchToDesktop(newDesktop)
{
global
if (curDesktop <> newDesktop)
{
GetCurrentWindows(curDesktop)
;WinGet, windows%curDesktop%, List,,, Program Manager ; get list of all visible windows
ShowHideWindows(curDesktop, false)
ShowHideWindows(newDesktop, true)
curDesktop := newDesktop
Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
return
}
; sends the given window from the current desktop to the given desktop
SendToDesktop(windowID, newDesktop)
{
global
RemoveWindowID(curDesktop, windowID)
; add window to destination desktop
windows%newDesktop% += 1
i := windows%newDesktop%
windows%newDesktop%%i% := windowID
WinHide, ahk_id %windowID%
Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
}
; sends the currently active window to the given desktop
SendActiveToDesktop(newDesktop)
{
WinGet, id, ID, A
SendToDesktop(id, newDesktop)
}
; removes the given window id from the desktop
RemoveWindowID(desktopIdx, ID)
{
global
Loop, % windows%desktopIdx%
{
if (windows%desktopIdx%%A_Index% = ID)
{
RemoveWindowID_byIndex(desktopIdx, A_Index)
Break
}
}
}
; this removes the window id at index from desktop number
RemoveWindowID_byIndex(desktopIdx, ID_idx)
{
global
Loop, % windows%desktopIdx% - ID_idx
{
idx1 := % A_Index + ID_idx - 1
idx2 := % A_Index + ID_idx
windows%desktopIdx%%idx1% := windows%desktopIdx%%idx2%
}
windows%desktopIdx% -= 1
}
; this builds a list of all currently visible windows in stores it in desktop
GetCurrentWindows(index)
{
global
WinGet, windows%index%, List,,, Program Manager ; get list of all visible windows
; now remove task bar “window” (is there a simpler way?)
Loop, % windows%index%
{
id := % windows%index%%A_Index%
WinGetClass, windowClass, ahk_id %id%
if windowClass = Shell_TrayWnd ; remove task bar window id
{
RemoveWindowID_byIndex(index, A_Index)
Break
}
}
}
; if show=true then shows windows of desktop %index%, otherwise hides them
ShowHideWindows(index, show)
{
global
Loop, % windows%index%
{
id := % windows%index%%A_Index%
if show
WinShow, ahk_id %id%
else
WinHide, ahk_id %id%
}
}
; show all windows from all desktops on exit
CleanUp:
Loop, %numDesktops%
ShowHideWindows(A_Index, true)
ExitApp

运行,看看下面代码你就知道怎么用了:

!1::SwitchToDesktop(1)
!2::SwitchToDesktop(2)
!3::SwitchToDesktop(3)
!4::SwitchToDesktop(4)

^!1::SendActiveToDesktop(1)
^!2::SendActiveToDesktop(2)
^!3::SendActiveToDesktop(3)
^!4::SendActiveToDesktop(4)

再啰嗦一下使用方法:Alt + 1 切换到第一个桌面。其他类推。Ctrl + Alt + 1 把当前窗口发送到 第一个桌面。另外,如果虚拟桌面不够用的话,再添加:

!5::SwitchToDesktop(5)

如果你的键盘按键够用的话,是可以支持无限多个虚拟桌面的。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息