Skip to content

Instantly share code, notes, and snippets.

@p3nj
Last active June 30, 2023 06:52
Show Gist options
  • Save p3nj/74a746df417aca243a249be2ad556ead to your computer and use it in GitHub Desktop.
Save p3nj/74a746df417aca243a249be2ad556ead to your computer and use it in GitHub Desktop.
# When HHKB is connected
ACTION=="add", SUBSYSTEM=="usb", ENV{XAUTHORITY}="/home/user/.Xauthority", ENV{DISPLAY}=":0", ATTRS{idVendor}=="0853", ATTRS{idProduct}=="0100", RUN+="/home/user/bin/hhkb add"
# When HHKB is disconnected.
ACTION=="remove", SUBSYSTEM=="usb", ENV{XAUTHORITY}="/home/user/.Xauthority", ENV{DISPLAY}=":0", ATTRS{idVendor}=="0853", ATTRS{idProduct}=="0100", RUN+="/home/user/bin/hhkb remove"
#!/bin/bash
# use $ xinput list to check your keyboard name
deviceName="Asus Keyboard"
# awk is the command to split return the string which is greped with command grep.
# In '{print $4 }', $n is the number of column of the string.
# You should be test it before put this into command down below.
builtInId=$(xinput list | grep $deviceName | awk '{ print $4 }' | grep -Eo '[0-9]{1,2}' | sort | head -n 1)
case $1 in
add)
xinput disable $builtInId
# dbus-launch is needed for send notification.
dbus-launch notify-send "HHKB Connected..." \ "Internal keyboard disabled !";;
remove)
xinput enable $builtInId
dbus-launch notify-send "HHKB Disconnected..." \ "Internal keyboard enabled !";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment