How to detect touchscreen devices from a script?

udev already classifies the input devices (See https://wiki.kubuntu.org/X/InputConfiguration), the supported flags are:

  • ID_INPUT

    All input devices have this flag.

  • ID_INPUT_MOUSE

    Touchscreens and tables have this flag as well, since by the type of events they can produce they act as a mouse.

  • ID_INPUT_TABLET

  • ID_INPUT_TOUCHSCREEN

  • ID_INPUT_JOYSTICK

  • ID_INPUT_KEY

    Keyboards have this, but also things like lid switches which have just a few buttons

  • ID_INPUT_KEYBOARD

So an easy way to check in the system under test has a touchscreen device is to parse the output of udevadm info --export-db for the following section:

P: /devices/pci0000:00/0000:00:14.0/usb2/2-7/2-7:1.0/input/input14
E: ABS=273800000000003
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-7/2-7:1.0/input/input14
E: EV=10000b
E: ID_BUS=usb
E: ID_INPUT=1
E: ID_INPUT_TOUCHSCREEN=1
E: ID_MODEL=Touchscreen
E: ID_MODEL_ENC=Touchscreen
E: ID_MODEL_ID=0100
E: ID_PATH=pci-0000:00:14.0-usb-0:7:1.0
E: ID_PATH_TAG=pci-0000_00_14_0-usb-0_7_1_0
E: ID_REVISION=1110
E: ID_SERIAL=ELAN_Touchscreen
E: ID_TYPE=hid
E: ID_USB_DRIVER=usbhid
E: ID_USB_INTERFACES=:030000:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=ELAN
E: ID_VENDOR_ENC=ELAN
E: ID_VENDOR_ID=04f3
E: KEY=400 0 0 0 0 0
E: MODALIAS=input:b0003v04F3p0100e0110-e0,1,3,14,k14A,ra0,1,2F,30,31,34,35,36,39,mlsfw
E: NAME="ELAN Touchscreen"
E: PHYS="usb-0000:00:14.0-7/input0"
E: PRODUCT=3/4f3/100/110
E: PROP=2
E: SUBSYSTEM=input
E: UDEV_LOG=3
E: UNIQ=""
E: USEC_INITIALIZED=815199186

The command to use is finally:

udevadm info --export-db | grep ID_INPUT_TOUCHSCREEN=1