https://github.com/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
https://github.com/FuPeiJiang/VD.ahk
autohotkey hotkeys virtual-desktop winapi windows
Last synced: 3 months ago
JSON representation
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
- Host: GitHub
- URL: https://github.com/FuPeiJiang/VD.ahk
- Owner: FuPeiJiang
- License: mit
- Created: 2020-11-21T22:25:12.000Z (almost 5 years ago)
- Default Branch: class_VD
- Last Pushed: 2025-03-20T00:20:58.000Z (7 months ago)
- Last Synced: 2025-03-20T01:26:28.513Z (7 months ago)
- Topics: autohotkey, hotkeys, virtual-desktop, winapi, windows
- Language: AutoHotkey
- Homepage:
- Size: 260 KB
- Stars: 404
- Watchers: 12
- Forks: 50
- Open Issues: 44
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome-github-stars - 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 -> (AutoHotkey)
README
# VD.ahk: Virtual Desktop
Windows 11 support, Windows Server 2022, [ahkv2: v2_port](https://github.com/FuPeiJiang/VD.ahk/tree/v2_port#readme)
### Just run the examples, everything explained inside
* Numpad1 to go to `Desktop 1`
* Numpad2 to go to `Desktop 2`
* Numpad3 to go to `Desktop 3`
```autohotkey
numpad1::VD.goToDesktopNum(1)
numpad2::VD.goToDesktopNum(2)
numpad3::VD.goToDesktopNum(3)
```
if you don't want VD switching animation, set `VD.animation_on:=false`* Win + x move VSCode to your current Desktop and WinActivate
* Win + e move "explorer replacement program" to your current Desktop and WinActivate
```autohotkey
#x::VD.MoveWindowToCurrentDesktop("ahk_exe Code.exe ahk_class Chrome_WidgetWin_1")
#e::VD.MoveWindowToCurrentDesktop("ahk_explorer ahk_exe AutoHotkey.exe")
```* Numpad4 to move the active window to `Desktop 1`
* Numpad5 to move the active window to `Desktop 2`
* Numpad6 to move the active window to `Desktop 3`
* here, I choose to follow the window
```autohotkey
numpad4::VD.MoveWindowToDesktopNum("A",1).follow()
numpad5::VD.MoveWindowToDesktopNum("A",2).follow()
numpad6::VD.MoveWindowToDesktopNum("A",3).follow()
```
```autohotkey
numpad7::VD.MoveWindowToDesktopNum("A",1)
numpad8::VD.MoveWindowToDesktopNum("A",2)
numpad9::VD.MoveWindowToDesktopNum("A",3)
```
...
```autohotkey
; wrapping / cycle back to first desktop when at the last
^#left::VD.goToRelativeDesktopNum(-1)
^#right::VD.goToRelativeDesktopNum(+1); move window to left and follow it
#!left::VD.MoveWindowToRelativeDesktopNum("A", -1).follow()
; move window to right and follow it
#!right::VD.MoveWindowToRelativeDesktopNum("A", 1).follow()
```you can remap everything
___
detect when the virtual desktop changes:
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:
* `createDesktop()`* rename desktop: `VD.setNameToDesktopNum("custom Desktop Name",desktopNum)`
* "Show this window on all desktops" corresponds to `VD.PinWindow(wintitle)`
* "Show windows from this app on all desktops" corresponds to `VD.PinExe(exe_path)`
- `getCount()` ;how many virtual desktops you now have
- pretty much everything virtual desktop, or so I think!
if there's anything missing/something you want: [create an issue](https://github.com/FuPeiJiang/VD.ahk/issues/new): I want to know what you're using it forhere's quick nice example: "get desktopNum of all windows"
```autohotkey
#Include %A_LineFile%\..\..\VD.ahkfoundProcesses := ""
; 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:
* Switching VD does not make icons (on the taskbar) flash
https://github.com/mzomparelli/zVirtualDesktop/issues/59#issue-227209226
> Sometimes when I switch desktop, the application that's focused on that desktop becomes highlighted in the task bar.
>
> Example:
> On desktop A, I have Firefox:
> 
>
> On desktop B I have Steam (note that Firefox is pinned to my task bar, which is why it's visible on this desktop):
> 
>
> When I switch from A to B, Steam becomes highlighted:
> 
> (It's possible to stop the blinking by explicitly selecting the blinking window with the mouse or alt+tab.)
>
> When I switch back to A, Firefox also becomes highlighted (and Steam stays visible in the taskbar because it is highlighted):
> 
>
> This doesn't always happen; I'm not sure if it depends on the programs or where the mouse/keyboard focus is when switching desktops. That said, it happens far too often, to the point where it defeats the point of having multiple desktops at all.
>
> (The problem isn't limited to Firefox and Steam, the same thing also happens with other programs like Explorer.)how ? `WinActivate` taskbar before switching and `WinMinimize` taskbar after arriving
* Switch VD reliably works in FULLSCREEN thanks to `SetTimer, pleaseSwitchDesktop, -50`
___
### if you don't use these headers, it will be slow:
```autohotkey
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SetBatchLines -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#KeyHistory 0
#WinActivateForceProcess, Priority,, H
SetWinDelay -1
SetControlDelay -1
```
___
if you want global functions style instead of a class:
eg: `VD_goToDesktopNum()` instead of `VD.goToDesktopNum()`
then visit branch `global_functions`
but it won't be updated
___
from https://github.com/MScholtes/VirtualDesktop/blob/812c321e286b82a10f8050755c94d21c4b69812f/VirtualDesktop11.cs#L161-L185
Windows 11 has more functionality,
if you need:
* MoveDesktop: `// move current desktop to desktop in index (-> index = 0..Count-1)`
* SetDesktopName
* SetDesktopWallpaper
* GetDesktopIsPerMonitor
* 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)