Disabling internal keyboard using udev

These scripts will disable internal keyboard automatically when mechanical keyboard connected. My keyboard is Keychron K2  . I'm using gnome shell under Wayland, Fedora 30

First, create two script which will run on device add and remove

$ vi /path/key_grab.sh

#!/bin/sh
wall "Grabbing keyboard"
/usr/bin/killall evtest
echo "/usr/bin/evtest --grab /dev/input/event2 > /dev/null" | at now



$ vi /path/key_grab_end.sh

#!/bin/sh
wall "Ungrab keyboard"
/usr/bin/killall evtest



Then edit udev rule in /etc/udev/rules.d/99-my.rules

ACTION=="add", SUBSYSTEM=="hid", ENV{HID_NAME}=="Keychron K2", RUN+="/path/key_grab.sh"
ACTION=="remove", SUBSYSTEM=="hid", ENV{HID_NAME}=="Keychron K2", RUN+="
/path/key_grab_end.sh"


Reload udev rules:

$ udevadm control --reload-rules && udevadm trigger


Finally, try to plug unplug USB Cable or connect/disconnect Bluetooth to trigger script

---

Tips: to find out internal keyboard device (/dev/input/event2)

$ libinput list-devices | grep -A1  "AT Translated"


Tips: to monitor udev hotplug use this command

$ udevadm monitor --environment --udev

Comments

Popular posts from this blog

Optimize SSD on Linux

Manually clean up zimbra zmcat/zmcpustat exploit

Ports to allow for whatsapp call