An AutoHotkey script for Windows that lets a user switch virtual desktops by pressing CapsLock and a number row key at the sime time (e.g. CapsLock + 2 to switch to Desktop 2). It also provides other features, such as customizing the key combinations, creation/deletion of desktops by hotkey, etc. (see Hotkeys section below).
Action | Keys |
---|---|
Switch to virtual desktop 1, 2, etc. (you can also use the Numpad) |
CapsLock + 1 CapsLock + 2 ... CapsLock + 9 |
Switch back to the last desktop used | CapsLock + Tab |
Switch to the virtual desktop on the left (auto-cycles from the first to the last desktop) |
CapsLock + A CapsLock + P |
Switch to the virtual desktop on the right (auto-cycles from the last to the first desktop) |
CapsLock + S CapsLock + N |
Create a new virtual desktop | CapsLock + C |
Delete the current virtual desktop | CapsLock + D |
Move the current window to another desktop, then switch to it Keys Q, W, etc. correspond to 1st, 2nd, etc. desktops |
CapsLock + Q CapsLock + W ... CapsLock + O |
Move the current window to the previous or the next desktop, then switch to it | CapsLock + ← CapsLock + → |
Note, CapsLock continues to function normally even when it is used as a modifier. But you can make the button do more useful things such as open overview, or disable it altogether.
If you'd like, you can enable the alternate configuration, to use Ctrl + Alt as hotkey combination keys instead of CapsLock (e.g. use Ctrl + Alt + 1 to switch to the Desktop 1, just as you would use CapsLock + 1).
Additional hotkeys, such as pinning a window or app on all workspaces, can be added as well.
You can also customize the hotkeys and actions as described in the section below.
This script creates more convenient hotkeys for switching virtual desktops in Windows 10. I built this to better mirror the mapping I use on linux (with dwm), and it's always annoyed me that Windows does not have better hotkey support for this feature (for instance, there's no way to go directly to a desktop by number).
Install AutoHotkey v1.1 or later, then run the desktop_switcher.ahk
script (open with AutoHotkey if prompted). You can disable the switching animation by opening "Adjust the appearance and performance of Windows" and then unselecting the checkmark "Animate windows when minimizing and maximizing".
This project relies partly on VirtualDesktopAccessor.dll (for moving windows to other desktops). This binary is included in this repository for convenience, and was recently updated to work with the 1809/1903≤ updates.
This may cause instability for users running older versions of Windows. If this is the case, download the older DLL, rename it to VirtualDesktopAccessor.dll
, and overwrite the previous DLL.
If a future Windows Update breaks the DLL again and updating your files from this repository doesn't work, you could try building the DLL yourself (given that it was since updated by its' creators).
To change the key mappings, modify the user_config.ahk
script and then run desktop_switcher.ahk
(program will restart if it's already running). Note, !
corresponds to Alt, +
is Shift, #
is Win, and ^
is Ctrl. A more detailed description of hotkeys can be found here. The syntax of the config file is HOTKEY::ACTION
. Here are some examples of the customization options.
Single line of code example | Meaning |
---|---|
!n::switchDesktopToRight() |
Hotkey: Alt + N Action: Switch to the desktop on the right |
#!space::switchDesktopToRight() |
Hotkey: Win + Alt + Space Action: Switch to the desktop on the right |
CapsLock & n::switchDesktopToRight() |
Hotkey: Capslock + N Action: Switch to the desktop on the right (& is necessary when using a non-modifier key such as Capslock) |
!n::switchDesktopToRight() |
Hotkey: Alt + N Action: Switch to the desktop on the right |
^space::send, #{tab} |
Hotkey: Ctrl + Space Action: Open Desktop Manager by sending Win + Tab |
A more detailed description of hotkeys can be found here: AutoHotkey docs.
You can find the explanation for the Desktop Manager hotkey here.
After any changes to the configuration the program needs to be closed and opened again.
You can make the script run on every boot with either of these methods.
- Press Win + R, enter
shell:startup
, then click OK - Create a shortcut to the
desktop_switcher.ahk
file here
Windows prevents hotkeys from working in windows that were launched with higher elevation than the AutoHotKey script (such as CMD or Powershell terminals that were launched as Administrator). As a result, Windows Desktop Switcher hotkeys will only work within these windows if the script itself is Run as Administrator
, due to the way Windows is designed.
You can do this by creating a scheduled task to invoke the script at logon. You may use 'Task Scheduler', or create the task in powershell as demonstrated.
# Run the following commands in an Administrator powershell prompt.
# Be sure to specify the correct path to your desktop_switcher.ahk file.
$A = New-ScheduledTaskAction -Execute "PATH\TO\desktop_switcher.ahk"
$T = New-ScheduledTaskTrigger -AtLogon
$P = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest
$S = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0
$D = New-ScheduledTask -Action $A -Principal $P -Trigger $T -Settings $S
Register-ScheduledTask WindowsDesktopSwitcher -InputObject $D
The task is now registered and will run on the next logon, and can be viewed or modified in 'Task Scheduler'.
Solution is described in #66.
Solution is described in #69.
How to see at a glance, which of the desktops am I currently on (i.e. show a number of the current desktop as a tray bar icon)?
Solution is described in #50.
- Thanks to Ciantic/VirtualDesktopAccessor (DLL) and sdias/win-10-virtual-desktop-enhancer (DLL usage samples), our code can now move windows between desktops.
To see debug messages, download SysInternals DebugView.
This script is intended to be lightweight in order to prioritize performance and robustness. For more advanced features (such as configuring different wallpapers on different desktops) check out https://github.com/sdias/win-10-virtual-desktop-enhancer.