From d544dfe9c3090890a5e3276b8ba47b8f8dfbe0da Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 13 Feb 2020 04:30:34 +0100 Subject: [PATCH] Add udev rule: swap caps_lock with escape on usb keyboards --- .scripts/inputctl.sh | 4 ++++ etc/udev/rules.d/00-usb-keyboard.rules | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 etc/udev/rules.d/00-usb-keyboard.rules diff --git a/.scripts/inputctl.sh b/.scripts/inputctl.sh index 769847f..9d7bba4 100755 --- a/.scripts/inputctl.sh +++ b/.scripts/inputctl.sh @@ -40,6 +40,10 @@ EOF # If no option is provided [ "$#" -eq 0 ] && help && exit +# Set required X variables +export DISPLAY=:0 +export XAUTHORITY="$XDG_DATA_HOME/xorg/Xauthority" + SCRIPT="$(basename "$0")" # Option handling while getopts ':h?d:k:s:' opt; do diff --git a/etc/udev/rules.d/00-usb-keyboard.rules b/etc/udev/rules.d/00-usb-keyboard.rules new file mode 100644 index 0000000..b154cb7 --- /dev/null +++ b/etc/udev/rules.d/00-usb-keyboard.rules @@ -0,0 +1,13 @@ +# -*- mode: conf -*- + +# When usb keyboard is plugged in, run inputctl script +# Requires: run as local user with X variables set (DISPLAY and XAUTHORITY) + +SUBSYSTEM=="usb", + ACTION=="add", + ATTRS{idVendor}=="04d9", + ATTRS{idProduct}=="0169", + OWNER="rick", + RUN+="/home/rick/.scripts/inputctl.sh -k on" + +# https://wiki.archlinux.org/index.php/Udev#Execute_on_VGA_cable_plug_in