Ubuntu – How to disable and enable keyboard on lenovo yoga

keyboardlenovo

I have a Lenovo Yoga 300. It works well with Ubuntu, but I have a problem with a keyboard lock.

As it is a Yoga model, it has different modes of usage. When I turn the screen it should lock the keyboard for a normal usage of tablet or tent mode, but it does not lock it.

Is there any key or command that I could use to lock keyboard and unlock it when I need? Even if there is a program for it, that would be helpful.

Best Answer

You can use xinput to achieve what you want. xinput is a utility to list available input devices, query information about a device and change input device settings. Open a terminal and execute xinput list - you will receive an output information which will read like this :

severus@Tux:~$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [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)]
    ↳ Video Bus                                 id=8    [slave  keyboard (3)]
    ↳ Power Button                              id=9    [slave  keyboard (3)]
    ↳ HP Truevision HD                          id=10   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=11   [slave  keyboard (3)]
    ↳ HP WMI hotkeys                            id=13   [slave  keyboard (3)]
    ↳ HP Wireless hotkeys                       id=14   [slave  keyboard (3)]

To lock a device execute this command : xinput --set-prop <device id> "Device Enabled" 0

Example :

To lock the keyboard : xinput --set-prop 11 "Device Enabled" 0 (11->device id from list)

To unlock it, xinput --set-prop <device id> "Device Enabled" 1

Caution! : Do not lock yourself out by locking all devices.

To lock for a given amount of time, say 5 minutes, do this :

xinput --set-prop <device id> "Device Enabled" 0 ; sleep 5m ; xinput --set-prop <Device id> "Device Enabled" 1

Note : Logging out and logging back in will unlock all devices.