#!/bin/sh # Press Logo+Alt+$K to turn $K into an inverted key. # Key down and up events for $K will be swapped. # Press Logo+Alt+$K again to return $K to a normal key. # Setup (in sway config); # dotool needs to be running for the virtual keyboard input to work # exec dotoold # usage: call this script from your sway config, with the key as the only argument: # exec ~/.config/sway/dotool_key_invert w S="$0" K="$1" A="$2" I="$3" # necessary due to https://github.com/swaywm/sway/issues/6961 and our use of --input-device swaymsg seat '*' keyboard_grouping none setup() { # unbind the key swaymsg -- unbindsym "$K" "$(dirname "$S")/dotool_other_keyboards" "$S" "$K" un # release the key to avoid holding it down forever echo "keyup $K" | dotoolc # bind the combination to `seton` swaymsg -- bindsym "Mod1+Mod4+$K" exec "'$S' '$K' on" } seton() { # bind the key "$(dirname "$S")/dotool_other_keyboards" "$S" "$K" bd # start holding down the key echo "keydown $K" | dotoolc # bind the combination to `setup` swaymsg -- bindsym "Mod1+Mod4+$K" exec "'$S' '$K' off" } case "$A" in bd) swaymsg -- bindsym --no-repeat --input-device="$I" "$K" exec "echo 'keyup $K' | dotoolc"; swaymsg -- bindsym --release --input-device="$I" "$K" exec "echo 'keydown $K' | dotoolc";; un) swaymsg -- unbindsym --no-repeat --input-device="$I" "$K"; swaymsg -- unbindsym --release --input-device="$I" "$K";; on) seton;; *) setup;; esac