findkeyboards revision 3e2147858f21943d5f4a781c60f33ac22c6096ed
341N/A#!/bin/sh -e
341N/A# Find "real" keyboard devices and print their device path.
341N/A# Author: Martin Pitt <martin.pitt@ubuntu.com>
341N/A#
943N/A# Copyright (C) 2009, Canonical Ltd.
341N/A#
341N/A# This program is free software; you can redistribute it and/or modify it
919N/A# under the terms of the GNU General Public License as published by
919N/A# the Free Software Foundation; either version 2 of the License, or
919N/A# (at your option) any later version.
919N/A#
919N/A# This program is distributed in the hope that it will be useful, but
919N/A# WITHOUT ANY WARRANTY; without even the implied warranty of
919N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
919N/A# General Public License for more details.
919N/A
919N/A# returns OK if $1 contains $2
919N/Astrstr() {
919N/A [ "${1#*$2*}" != "$1" ]
919N/A}
919N/A
919N/A# returns OK if $1 contains $2 at the beginning
919N/Astr_starts() {
919N/A [ "${1#$2*}" != "$1" ]
341N/A}
341N/A
341N/Astr_line_starts() {
341N/A while read a; do str_starts "$a" "$1" && return 0;done
493N/A return 1;
341N/A}
341N/A
962N/A# print a list of input devices which are keyboard-like
341N/Akeyboard_devices() {
911N/A # standard AT keyboard
962N/A for dev in `udevadm trigger --dry-run --verbose --property-match=ID_INPUT_KEYBOARD=1`; do
962N/A walk=`udevadm info --attribute-walk --path=$dev`
911N/A env=`udevadm info --query=env --path=$dev`
341N/A # filter out non-event devices, such as the parent input devices which have no devnode
341N/A if ! echo "$env" | str_line_starts 'DEVNAME='; then
341N/A continue
341N/A fi
341N/A if strstr "$walk" 'DRIVERS=="atkbd"'; then
341N/A echo -n 'AT keyboard: '
341N/A elif echo "$env" | str_line_starts 'ID_USB_DRIVER=usbhid'; then
341N/A echo -n 'USB keyboard: '
341N/A else
341N/A echo -n 'Unknown type: '
392N/A fi
604N/A udevadm info --query=name --path=$dev
646N/A done
812N/A
688N/A # modules
688N/A module=$(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*Extra Buttons')
688N/A module="$module
688N/A $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*extra buttons')"
688N/A module="$module
688N/A $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='Sony Vaio Keys')"
688N/A for m in $module; do
688N/A for evdev in $m/event*/dev; do
688N/A if [ -e "$evdev" ]; then
688N/A echo -n 'module: '
688N/A udevadm info --query=name --path=${evdev%%/dev}
688N/A fi
688N/A done
688N/A done
688N/A}
688N/A
688N/Akeyboard_devices
688N/A