Switching Windows 10 Virtual Desktops using Swipe Gestures
I recently switched to Windows 10 to use the new Windows Subsystem for Linux. After switching, I’ve found Windows 10’s built in Virtual Desktops to be very useful. Previously, I’ve used VirtuaWin for virtual desktops on Windows, so having it built-in is very nice. However, the other GUI OSes I use, OS X and Ubuntu, both support swipe gestures to switch between desktops or workspaces. Therefore, I wanted to add swipe gestures for switching between virtual desktops on Windows 10.
Touchpad brands
I have a touchpad by Synaptics, which is (one of?) the largest laptop touchpad producers. The script below has been tested only on my Synaptics touchpad. It should work on most Synaptics touchpads, as long as you have the latest driver. Someone figured out how to enable swiping to switch virtual desktops on ElanTech touchpads and posted it on Reddit. If you have a touchpad from a different company such as Alps or Cirque, you can try modifying my script.
AutoHotkey
I’m using AutoHotkey to add the swipe gestures. AutoHotkey allows you to map your computer’s inputs to other inputs. For example, when you press a certain key, AutoHotkey can make your programs think you pressed a different key. Synaptics implements gestures as a mapping from touchpad inputs to Windows keyboard shortcuts. For example, using 3 fingers to swipe left or right triggers the keyboard shortcut for switching between active windows (Ctrl + Alt + Tab + Enter and Ctrl + Alt + Tab + Shift + Enter). We can use AutoHotkey to capture these inputs and transform them into the inputs that switches the virtual desktops.
The script
Here’s the AutoHotkey script to transform Synaptics 3-figure swipe gestures into keyboard shortcuts to switch between virtual desktops:
swipeDirection := "" ^!Tab:: swipeDirection := "L" return ^!+Tab:: swipeDirection := "R" return $ Enter:: if (not swipeDirection) { SendInput {Enter} } else if (swipeDirection = "L") { SendInput ^#{Left} } else if (swipeDirection = "R") { SendInput ^#{Right} } swipeDirection := "" return
Disclaimer: I’m by no means an AutoHotkey expert. If you know a way to improve this script, please let me know in the comments! It took me a while to come up with this script because the Enter key is pressed after the Ctrl, Alt, and Tab keys are released. Depending on how long you swipe for, the delay between pressing ^!Tab and Enter is variable. By adding a swipeDirection variable to maintain state, it doesn’t matter how long it takes to swipe.