I have a simple script to turn my keyboard of written using xinput. How can I get the current state of the device (enabled or disabled) so that when I run the script I can don't have to specify on/off, it just reverses the state?(warning - this might turn your keyboard off; handle with care)#!/bin/bash  case $1 in    on)    export DISPLAY=:0        xinput set-prop 14 Device Enabled 1    killall -q onboard     ;;    off)    onboard &> /dev/null 2>&1    export DISPLAY=:0    xinput set-prop 14 Device Enabled 0    ;;esacnow I run: ./my_keyboard on if the keyboard is off. I would like to just run ./my_keyboard and have it change state. There doesn't appear to be anything in the xinput docs (query-state does not have the property).
using xinput to get device state
keyboard shortcuts;keyboard;xinput
To directly answer your question: You can parse the output of this command to get the state of the device:xinput list-props $DEVICE_NAME_OR_IDI think the device id may vary, so I recommend using the name. I'm not sure about this though.I wrote a small script to toggle my own touch pad:#!/bin/bash                                                                      DEVICE='SynPS/2 Synaptics TouchPad'                                              enabled=$(xinput list-props $DEVICE | awk '/^\tDevice Enabled \([0-9]+\):\t[01]/ {print $NF}')case $enabled in                                                                  0)                                                                                xinput enable $DEVICE                                                         echo $DEVICE enabled                                                          ;;                                                                            1)                                                                                xinput disable $DEVICE                                                         echo $DEVICE disabled                                                          ;;                                                                            *)                                                                                echo                                                                            xinput list --name-only                                                         ;;                                                                          esac