Script to disable & enable touchpads

I constantly touch the touchpad when I type. I also normally use an external mouse when I’m on my laptop. I seldom really need it, but I will sometimes want to switch it on (or off).

First you need to find the name of your touchpad in the xinput list:

$ xinput list

⎡ Virtual core pointer                     id=2 [master pointer  (3)]

⎜   ↳ Virtual core XTEST pointer               id=4 [slave  pointer  (2)]

⎜   ↳ Razer Razer Imperator                   id=10 [slave  pointer  (2)]

⎜   ↳ Razer Razer Imperator                   id=11 [slave  pointer  (2)]

⎜   ↳ PS/2 Mouse                               id=13 [slave  pointer  (2)]

⎜   ↳ AlpsPS/2 ALPS GlidePoint                 id=14 [slave  pointer  (2)]

⎣ Virtual core keyboard                   id=3 [master keyboard (2)]

    ↳ Virtual core XTEST keyboard             id=5 [slave  keyboard (3)]

    ↳ Sony Vaio Keys                           id=6 [slave  keyboard (3)]

    ↳ Video Bus                               id=7 [slave  keyboard (3)]

    ↳ Power Button                             id=8 [slave  keyboard (3)]

    ↳ USB 2.0 Camera                           id=9 [slave  keyboard (3)]

    ↳ AT Translated Set 2 keyboard             id=12 [slave  keyboard (3)]

So in my case the touchpad is most likely: PS/2 Mouse on id 13.

You can easily identify if the device is “on” (enabled):

$ xinput list-props “PS/2 Mouse” 

Device ‘PS/2 Mouse’:

Device Enabled (144): 1

Coordinate Transformation Matrix (146): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000

Device Accel Profile (267): 0

Device Accel Constant Deceleration (268): 1.000000

Device Accel Adaptive Deceleration (269): 1.000000

Device Accel Velocity Scaling (270): 10.000000

Evdev Axis Inversion (271): 0, 0

Evdev Axes Swap (273): 0

Axis Labels (274): “Rel X” (154), “Rel Y” (155)

Button Labels (275): “Button Left” (147), “Button Middle” (148), “Button Right” (149), “Button Wheel Up” (150), “Button Wheel Down” (151)

Evdev Middle Button Emulation (276): 0

Evdev Middle Button Timeout (277): 50

Evdev Wheel Emulation (278): 0

Evdev Wheel Emulation Axes (279): 0, 0, 4, 5

Evdev Wheel Emulation Inertia (280): 10

Evdev Wheel Emulation Timeout (281): 200

Evdev Wheel Emulation Button (282): 4

Evdev Drag Lock Buttons (283): 0

 Now create yourself a little file (eg: “touchpad”):

# toggle synaptic touchpad on/off

SYNSTATE=$(xinput list-props “PS/2 Mouse” | grep Enabled | grep -Eo ‘.$’)

if [ $SYNSTATE = 0 ]; then xinput set-int-prop “PS/2 Mouse” “Device Enabled” 8 1

else xinput set-int-prop “PS/2 Mouse” “Device Enabled” 8 0; fi

dengar@dengar-vaio:/usr/bin$ $ xinput list-props “PS/2 Mouse” 

This should sort you out. Don’t forget to  change the name of your actual device, remember mine is “PS/2 Mouse”

Next you need to make the file executable:

sudo chmod +x touchpad

Now, to have that file available from the command line, simply copy it to /usr/bin.

Switching off the Synaptic touchpad in Linux

If you are anything like me, you will find it annoying that your hand sometimes brushes against the touchpad of your laptop and – bang – the mouse has moved, the courser is misplaced and you have to correct what you have just written on…

Normally switching off the touchpad on laptops is easy, there will be a hotkey, but in Linux you will find not all ACPI options are working well and properly – or at all.

But it can be quite simple switching the touchpad on and off.

We need one step of preperation:

Open your xorg.conf as root (in my distro):
# sudo gedit /etc/X11/xorg.conf

Somewhere there should be this section:

Section “InputDevice”
Identifier “Synaptics Touchpad”
Driver “synaptics”
Option “SendCoreEvents” “true”
Option “Device” “/dev/psaux”
Option “Protocol” “auto-dev”
Option “HorizEdgeScroll” “0”
Option “SHMConfig” “on”
EndSection

It is important that you have this in there:
Option “SHMConfig” “on”

If that’s done, save and exit.

Next you will need to restart your graphic interface (so xorg.conf get’s loaded again). Simply press CTRL + ALT + BACKSPACE

Great, that’s done – now you can do this (as root):
# synclient touchpadoff=1
to switch it off, and:
# synclient touchpadoff=0
to switch it back on…