AI chat

Hold my side button and swipe to switch desktops

Assuming you want to hold Mouse4 (the back side button) and flick left or right to switch virtual desktops, here is a complete script.

Because modifying or swallowing mouse movement with OnMove requires intercepting physical motion, this script requires a Rebind Link.

How it works

  1. Button handling: When you press Mouse4, OnDown swallows the initial click. If you release the button without moving past the threshold, OnUp sends the original Mouse4 press so you can still use it as a normal back button.
  2. Gesture tracking: While holding Mouse4, OnMove accumulates horizontal mouse delta (accum_x) and swallows cursor movement so the pointer doesn't slide across your screen.
  3. Desktop switching: Once horizontal motion exceeds the distance threshold, switch_desktop() triggers the OS shortcut (Ctrl + Win + Left/Right on Windows; Ctrl + Left/Right on macOS) via HID.Combo and resets the accumulator, allowing multiple swipes in a row if desired.

Learn more