findkeyboards 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh -e
  2. # Find "real" keyboard devices and print their device path.
  3. # Author: Martin Pitt <martin.pitt@ubuntu.com>
  4. #
  5. # Copyright (C) 2009, Canonical Ltd.
  6. #
  7. # This program is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. # returns OK if $1 contains $2
  17. strstr() {
  18. [ "${1#*$2*}" != "$1" ]
  19. }
  20. # returns OK if $1 contains $2 at the beginning
  21. str_starts() {
  22. [ "${1#$2*}" != "$1" ]
  23. }
  24. str_line_starts() {
  25. while read a; do str_starts "$a" "$1" && return 0;done
  26. return 1;
  27. }
  28. # print a list of input devices which are keyboard-like
  29. keyboard_devices() {
  30. # standard AT keyboard
  31. for dev in `udevadm trigger --dry-run --verbose --property-match=ID_INPUT_KEYBOARD=1`; do
  32. walk=`udevadm info --attribute-walk --path=$dev`
  33. env=`udevadm info --query=env --path=$dev`
  34. # filter out non-event devices, such as the parent input devices which have no devnode
  35. if ! echo "$env" | str_line_starts 'DEVNAME='; then
  36. continue
  37. fi
  38. if strstr "$walk" 'DRIVERS=="atkbd"'; then
  39. echo -n 'AT keyboard: '
  40. elif echo "$env" | str_line_starts 'ID_USB_DRIVER=usbhid'; then
  41. echo -n 'USB keyboard: '
  42. else
  43. echo -n 'Unknown type: '
  44. fi
  45. udevadm info --query=name --path=$dev
  46. done
  47. # modules
  48. module=$(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*Extra Buttons')
  49. module="$module
  50. $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='*extra buttons')"
  51. module="$module
  52. $(udevadm trigger --verbose --dry-run --subsystem-match=input --attr-match=name='Sony Vaio Keys')"
  53. for m in $module; do
  54. for evdev in $m/event*/dev; do
  55. if [ -e "$evdev" ]; then
  56. echo -n 'module: '
  57. udevadm info --query=name --path=${evdev%%/dev}
  58. fi
  59. done
  60. done
  61. }
  62. keyboard_devices