#!/bin/bash t=$(grep -Hsi keyboard /sys/class/input/input*/name | sed -e 's#.*input\([0-9]*\)/name.*#event\1#') unset t if [[ -z "${t}" ]]; then t=$(grep -Hsi keyboard /sys/class/input/event*/device/driver/description | grep -o 'event[0-9]\+') if [[ -z "${t}" ]]; then for i in /sys/class/input/input* ; do if [ "$((0x$(cat $i/capabilities/ev) & 0x100002))" = "1048578" ]; then t=$(echo $i | sed -e 's#.*input\([0-9]*\)#event\1#') fi done if [[ -z "${t}" ]]; then # Try an alternative method of finding the event device. The idea comes # from Bombadil . We're couting on the keyboard controller # being the first device handled by kbd listed in input/devices. t=$(/bin/grep -s -m 1 '^H: Handlers=kbd' /proc/bus/input/devices | grep -o 'event[0-9]*') echo "got $t using method #4" else echo "got $t using method #3" fi else echo "got $t using method #2" fi else echo "got $t using method #1" fi