How to detect touchscreen devices from a script?

14,612

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
Share:
14,612
Sylvain Pineau
Author by

Sylvain Pineau

I'm an early user and advocate of Linux, and more generally Open Source Software, in the business world. I've been around with computers and particularly linux for some time now, and during all these years I've been using and promoting opensource technologies. I started using Linux in 1995 with a French Slackware, called Kheops. My first contact with Ubuntu was in 2006 with Edgy. Former Perl Monger, my preferred language is now Python. I know about web standards and design, HTML/CSS, and some QML/Javascript. The early years of my career were spent developing the French high speed train (TGV) RTOS. My professional activities also led me to several QA related positions and to Android phones integration before joining Canonical in 2010. I'm now working for the Hardware Certification Team at Canonical.

Updated on September 18, 2022

Comments

  • Sylvain Pineau
    Sylvain Pineau over 1 year

    I'm looking for a reliable way to detect if a laptop has a touchscreen device from a script. I know I can parse the output of:

    $ xinput --list
    ⎡ Virtual core pointer                          id=2    [master pointer  (3)]
    ⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
    ⎜   ↳ ELAN Touchscreen                          id=10   [slave  pointer  (2)]
    ⎜   ↳ SynPS/2 Synaptics TouchPad                id=12   [slave  pointer  (2)]
    ⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
        ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
        ↳ Power Button                              id=6    [slave  keyboard (3)]
        ↳ Video Bus                                 id=7    [slave  keyboard (3)]
        ↳ Power Button                              id=8    [slave  keyboard (3)]
        ↳ TOSHIBA Web Camera - HD                   id=9    [slave  keyboard (3)]
        ↳ AT Translated Set 2 keyboard              id=11   [slave  keyboard (3)]
        ↳ Toshiba input device                      id=13   [slave  keyboard (3)]
    

    But ideally I'd prefer not having to rely on a product name. Actually I'm looking for a flag clearly stating that such device exist on my test system.