Sample Header Ad - 728x90

How to prevent attaching headphones from altering the keyboard setup?

0 votes
1 answer
48 views
I have a Dell Latitude 7400 laptop running Linux Mint 20.1, with Linux 5.4 and Cinnamon 4.8.6. When I log in, I run this script. 1 #!/bin/sh 2 3 /usr/bin/killall xcape 2>/dev/null 4 /usr/bin/xmodmap -e 'remove Lock = Caps_Lock' 2>/dev/null 5 /usr/bin/setxkbmap -option 'ctrl:nocaps' 6 /usr/bin/xcape Lines 4 and 5 turn the Capslock key into a Control key, and xcape (line 6) turns the left Control keys (especially the one that was just the Capslock key) into Escape keys when pressed alone, or a Control key when pressed with other keys. If I have to run the script again, the killall on line 3 ends any previous xcape instances before starting a new one. I have a Logitech USB headphones + microphone headset, and fairly generic Space Travel brand Bluetooth earbuds. Whenever I plug the headset in, or connect the earbuds to the laptop via Bluetooth, it undoes the entire effect of the script, and the Capslock key is again just a Capslock key. This has happened with Monoprice brand headphones as well, although I no longer have those headphones to test now. How can I prevent connecting audio peripherals from interfering with the way I have the keyboard set up, or how can I detect when it happens and have the script above run again? I use vim, and having an Escape key no longer work as an Escape key can be very disruptive. Thank you.
Asked by neniu (109 rep)
Jun 12, 2025, 10:30 PM
Last activity: Jun 13, 2025, 06:17 AM