FuPeiJiang / VD.ahk

Windows Virtual Desktop, AutoHotkey, Windows 11 support, Windows Server 2022, switch desktop, move window(wintitle) to current desktop; createDesktop, PinWindow, getCount, getDesktopNumOfWindow -> mute all windows in Virtual Desktop
MIT License
319 stars 45 forks source link
autohotkey hotkeys virtual-desktop winapi windows

VD.ahk: Virtual Desktop

Windows 11 support, Windows Server 2022, ahkv2: v2_port

Just run the examples, everything explained inside

; move window to left and follow it

!left::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", -1))

; move window to right and follow it

!right::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", 1))


you can remap everything
___
detect when the virtual desktop changes:<br>
create a hotkey to return you to the **previous desktop**
```ahk
#Include %A_LineFile%\..\VD.ahk
VD.RegisterDesktopNotifications()
VD.CurrentVirtualDesktopChanged:=Func("CurrentVirtualDesktopChanged")
VD.previous_desktopNum:=1
CurrentVirtualDesktopChanged(desktopNum_Old, desktopNum_New) {
  VD.previous_desktopNum:=desktopNum_Old
}
Numpad0::VD.goToDesktopNum(VD.previous_desktopNum)

also has:

here's quick nice example: "get desktopNum of all windows"

#Include %A_LineFile%\..\..\VD.ahk

foundProcesses := ""
; Make sure to get all windows from all virtual desktops
DetectHiddenWindows On
WinGet, id, List
Loop %id%
{
    hwnd := id%A_Index%
    ;VD.getDesktopNumOfWindow will filter out invalid windows
    desktopNum_ := VD.getDesktopNumOfWindow("ahk_id" hwnd)
    If (desktopNum_ > -1) ;-1 for invalid window, 0 for "Show on all desktops", 1 for Desktop 1
    {
        WinGet, exe, ProcessName, % "ahk_id" hwnd
        foundProcesses .= desktopNum_ " " exe "`n"
    }
}

MsgBox % foundProcesses

cool fixes:

how ? WinActivate taskbar before switching and WinMinimize taskbar after arriving

Process, Priority,, H

SetWinDelay -1 SetControlDelay -1


___
if you want global functions style instead of a class:<br>
eg: `VD_goToDesktopNum()` instead of `VD.goToDesktopNum()`<br>
then visit branch `global_functions`<br>
but it won't be updated
___
from https://github.com/MScholtes/VirtualDesktop/blob/812c321e286b82a10f8050755c94d21c4b69812f/VirtualDesktop11.cs#L161-L185<br>
Windows 11 has more functionality,<br>
if you need:<br>
* MoveDesktop: `// move current desktop to desktop in index (-> index = 0..Count-1)`<br>
* SetDesktopName<br>
* SetDesktopWallpaper<br>
* GetDesktopIsPerMonitor<br>
* etc.
* or anything else that's not On this list

[create an issue](https://github.com/MScholtes/VirtualDesktop/issues/new)
saying what function(s) you need, what you'll be using it for (I'm curious)