up vote 4 down vote favorite
1
share [fb]

How can one programmatically "freeze" the Keyboard & Mouse temporarily, so that no one could mess with the system?

There are several possibilities where this is useful. For instance, I have a laptop and I want to make sure no one uses it while I leave, even if somebody knows the password or can guess it (like wife or children), as well as depressing thieves' appetite (as it seems dis-functioning). or I'm doing something remotely so I want to make sure the user at the computer doesn't disturb.

link|improve this question
2  
Related: similar question on OSX – Gilles Jul 21 at 20:55
@Gilles: thanks for the good work. – Philomath Jul 21 at 22:06
feedback

4 Answers

up vote 5 down vote accepted

Assuming your GUI is X-based (as almost all UNIX GUIs are), use xinput.

First, list your devices:

$ xinput --list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Windows mouse                             id=6    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
↳ Windows keyboard                          id=7    [slave  keyboard (3)]

List the details for your mouse (id=6 in our example):

$ xinput --list-props 6
Device 'Windows mouse':
    Device Enabled (112):   1
    Coordinate Transformation Matrix (114): 1.000000, 0.000000, 0.000000, 0.000000,   1.000000, 0.000000, 0.000000, 0.000000, 1.000000
    Device Accel Profile (222):     0
    Device Accel Constant Deceleration (223):       1.000000
    Device Accel Adaptive Deceleration (224):       1.000000
    Device Accel Velocity Scaling (225):    10.000000

Now disable it:

$ export DISPLAY=:0
$ xinput set-int-prop 6 "Device Enabled" 8 0

To enable it do:

$ xinput set-int-prop 6 "Device Enabled" 8 1

The same goes for the keyboard, just replace the int-prop number with the proper id.
Tested and worked on cygwin.

Of course, you have to plan beforehand how will you enable your devices again. such as schedule it on cron, re-enable it remotely, or disable just one of them in first place.

link|improve this answer
No other answer here answers the question. – Philomath Jul 28 at 22:48
feedback

Your answer is probably best for your second use case (doing something remotely), but probably not for your first (being away from keyboard). How would you run xinput again to restore access when you return?

The standard solution to locking the system while away from it is XScreenSaver, which is installed by default in most distros. If configured to lock the keyboard, it will prompt for your password before unlocking it.

link|improve this answer
I have updated. – Philomath Jul 21 at 23:53
feedback

If you are using a Desktop Enviromnet and or login manager, (GNOME,KDE,XFCE,LXDE) almost all of them have a lock screen function where you have to type in your password to get back to your programs.

However since that is really simple i sense your problem is more complex / different.

link|improve this answer
I have updated. – Philomath Jul 21 at 23:53
feedback

Depending on your hardware, you can remove the modules, controlling your hardware. I have such a script, touchpadtoggle, to enable and disable my touchpad.

lsmod | grep -q psmouse && rmmod psmouse || modprobe psmouse

But the keyboard doesn't seem to have a module associated, and the psmouse-module will only work occasionally.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.