Disable / enable keyboard and mouse in Linux

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

Sometimes, you may need to disable mouse and keyboard on a remote server / PC running X (i.e. over SSH) and Linux (or any other operating system running X).

Here is how to do it:

  • First, list the devices your X sees:
$ xinput --list
"Virtual core pointer"  id=0    [XPointer]
"Virtual core keyboard" id=1    [XKeyboard]
"Keyboard2"     id=2    [XExtensionKeyboard]
"Mouse2"        id=3    [XExtensionKeyboard]


  • Now, list details for the mouse (id=3):
$ xinput --list-props 3
Device 'Mouse2':
        Device Enabled (119):   1
        Evdev Reopen Attempts (254):    10
        Evdev Axis Inversion (257):     0, 0
        Evdev Axis Calibration (258):   <no items>
        Evdev Axes Swap (259):  0
        Evdev Middle Button Emulation (260):    2
        Evdev Middle Button Timeout (261):      50
        Evdev Wheel Emulation (262):    0
        Evdev Wheel Emulation Axes (263):       0, 0, 4, 5
        Evdev Wheel Emulation Inertia (264):    10
        Evdev Wheel Emulation Timeout (265):    200
        Evdev Wheel Emulation Button (266):     4
        Evdev Drag Lock Buttons (267):  0


  • Disable the mouse:
$ export DISPLAY=:0
$ xinput set-int-prop 3 "Device Enabled" 8 0


  • Enable the mouse again:
$ xinput set-int-prop 3 "Device Enabled" 8 1


  • Disable the keyboard:
$ xinput set-int-prop 2 "Device Enabled" 8 0


  • Enable the keyboard again:
$ xinput set-int-prop 2 "Device Enabled" 8 1


  • You may find more details in "man xinput".