Skip to content

Instantly share code, notes, and snippets.

@bootandy
Created September 30, 2026 19:12
Show Gist options
  • Select an option

  • Save bootandy/6c87acedbdb6dfa5aed0b13f1944c145 to your computer and use it in GitHub Desktop.

Select an option

Save bootandy/6c87acedbdb6dfa5aed0b13f1944c145 to your computer and use it in GitHub Desktop.
Fix mouse script
# requires: sudo apt-get install inputplug
# cp <this> to .config/kvm-hotplug.sh
#!/bin/bash
# inputplug triggers this script on input changes.
# $1 = Event Type (e.g., XIDeviceEnabled), $2 = Device ID
if [ "$1" = "XIDeviceEnabled" ]; then
# Give Xorg a split second to finish registering the hardware
sleep 0.5
# 1. FIX THE MOUSE BUTTONS
# Dynamically find the mouse ID by matching 'Left'
mouseid=$(xinput | grep -i "Left" | sed -n 's/.*id=\([0-9]*\).*/\1/p' | head -n 1)
if [ -n "$mouseid" ]; then
xinput set-button-map "$mouseid" 3 1 8 4 5 6 7 9 2 10 11 12 13 14 15
fi
# 2. FORCE THE KEYBOARD OVERRIDES (Safety backup for the KVM)
setxkbmap -option "caps:swapescape,ctrl:swap_lalt_lctl"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment