Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am an avid keyboard user, but I still need the mouse every now and then. To minimize the hand travel, I have the mouse located below my keyboard. (On a side note, using the mouse this way feels more natural to my hand.)

I am currently using unclutter to hide the pointer while I don’t use the mouse. Unfortunately, I am nudging it at times while typing, which causes the pointer to reappear. Sometimes this will move the pointer over another window, which in turn takes the focus away from my current window. (I am using sloppy focus, and changing this is not an option.)

I am now searching for a possibility to not only hide the pointer after a certain amount of idle time, but disable the mouse altogether. Clicking any mouse button or using the mouse wheel should then re-enable the mouse.

share|improve this question

2 Answers 2

up vote 12 down vote accepted

First thing that we need to accomplish is turning off mouse, but only in X. For this we could use xinput.

We need to discover input devices that are connected to computer (to X server):

pbm@tauri ~ $ xinput list
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ A4Tech USB Mouse                          id=10   [slave  pointer  (2)]
⎜   ↳ Macintosh mouse button emulation          id=11   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
     [...]

Device that we need to use is A4Tech USB Mouse with id=10. Next we need to check properties of that device:

pbm@tauri ~ $ xinput list-props "A4Tech USB Mouse"
Device 'A4Tech USB Mouse':
       Device Enabled (121):   1
       [....]

To turn off device we need to change property Device Enabled:

xinput set-prop DEV PROP STATE
xinput set-prop "A4Tech USB Mouse" "Device Enabled" 0

To turn it on:

xinput set-prop "A4Tech USB Mouse" "Device Enabled" 1

Next thing is to do it automatically... ;) In this example we will be disabling mouse by keyboard shortcut and enable it by pressing left + right mouse button.

For this we could use actkbd - keyboard (but not only) shortcut daemon that works outside of X server.

First we need to create empty configuration file for actkbd: touch /etc/actkbd.conf. Next thing is to discover devices connected to computer:

pbm@tauri ~ $ cat /proc/bus/input/devices 
I: Bus=0003 Vendor=046d Product=c312 Version=0110
N: Name="BTC USB Multimedia Keyboard"
P: Phys=usb-0000:00:1d.0-1.6/input0
S: Sysfs=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.6/2-1.6:1.0/input/input6
U: Uniq=
H: Handlers=kbd event3 
B: EV=120013
B: KEY=1000000000007 ff9f207ac14057ff febeffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=7

I: Bus=0003 Vendor=09da Product=000a Version=0110
N: Name="A4Tech USB Mouse"
P: Phys=usb-0000:00:1d.0-1.5/input0
S: Sysfs=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/2-1.5:1.0/input/input8
U: Uniq=
H: Handlers=mouse1 event5 
B: EV=17
B: KEY=ff0000 0 0 0 0
B: REL=343
B: MSC=10

[...]

In this part most interesting for use are names and handlers of keyboard and mouse devices.

First we handle turning off mouse by keyboard shortcut, so we need to discover key ids:

pbm@tauri ~ $ sudo actkbd -s -d /dev/input/event3
Keys: 29+41+42 //we need to press keys that will turn off mouse, 29+41+42 is Ctrl + Shift + `

When we know what are keys ids we need to put them to config file (/etc/actkbd.conf):

29+41+42:::sudo -u pbm DISPLAY=:0 xinput set-prop "A4Tech USB Mouse" "Device Enabled" 0

To test it out we need to run actkbd in daemon mode:

pbm@tauri ~ $ sudo actkbd -d /dev/input/event3 -D

In the same way we need to handle "turn on" event:

  1. Check handlers of mouse device
  2. Check key codes of left+right mouse button using actkbd
  3. Put it to actkbd.conf
  4. Run actkbd daemon to monitor mouse input device

Running daemons could be realized as init script or autorun script in environment.

To automatically turning mouse off we could monitor input device (cat /dev/input/event5) and turn it off when there is no input...

I hope that my short intro will help you... ;)

share|improve this answer
    
Thanks for the hint with actkbd! After posting my question, I already had figured out to use xinput, but I didn’t find out how I would re-enable the mouse by pressing mouse buttons. –  igor Dec 6 '10 at 10:12
    
This is a very well written answer. –  pjc50 Feb 15 '11 at 13:15
    
Thanks for that info, especially for the hint with atkkbd –  user6557 Apr 13 '11 at 13:29
    
Instead of using --set-prop option along with “Device Enabled/Disabled” property, one can also use --enable and --disable options as well, e.g. xinput --enable [device] and xinput --disable [device]. –  thebodzio Feb 7 '13 at 3:38

Have you tried a "Pointer Capture" Gnome panel applet?

The mouse pointer can be locked into an area of the screen so the pointing device is free for other tasks. For example, this capability allows a powerchair user to control both the powerchair and the mouse pointer with a single powerchair joystick

The Pointer Capture panel applet creates such an area on the panel, into which the user can lock the pointer until released in a determined way.

The Pointer Capture panel applet can be installed by right-clicking the GNOME Desktop menu bar / system panel, selecting Add to Panel, choosing Pointer Capture and clicking the Add button

In case the description from gnome.org isn't clear, this will create an area in the panel where when the mouse enters (or you clic), the cursor will disappear and won't reappear until a defined action occurs, for example a second click. Sounds like exactly what you need?

share|improve this answer
    
I have used this but created some problems. I was not able to use Alt + F1 to open by applications menu. I don't know what caused that. I am a ubuntu user. –  balki Aug 4 '11 at 17:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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