First thing that we need to accomplish is turning off mouse, but only in X. For this we could use
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
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"
H: Handlers=kbd event3
B: KEY=1000000000007 ff9f207ac14057ff febeffdfffefffff fffffffffffffffe
I: Bus=0003 Vendor=09da Product=000a Version=0110
N: Name="A4Tech USB Mouse"
H: Handlers=mouse1 event5
B: KEY=ff0000 0 0 0 0
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 (
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:
- Check handlers of mouse device
- Check key codes of left+right mouse button using
- Put it to
- 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... ;)