Switch Automatically Mouse and Touchpad

October 27, 2007

I’ve been working for a bit on creating a script that can switch the touchpad on and off for better use with the mouse. Now by using a mouse I don’t have to keep my hands propped to avoid contact with the touchpad when I type. A while back I showed the users the script I had used to do this, but there turns out to be even a simpler-means to do it.

Before I was required to open the terminal to run the script, but using udev is much easier.

Udev processes inputs and can trigger actions or even run programs at the trigger. Once I learned the right lines to write into a udev rule, the toggling of mouse and touchpad is self-acting.

Open a new rule

vim /etc/udev/rules.d/10-local.rules

This should be able to work on basically on any PC.

ACTION=="add", SUBSYSTEM=="input", ID_CLASS="mouse", RUN+="/usr/bin/synclient TouchpadOff=1"
ACTION==”remove”, SUBSYSTEM==”input”, ID_CLASS=”mouse”, RUN+=”/home/todd/.scripts/mouse-touchpad-toggle-on”

A person could just use synclient again to switch on the touchpad once more, but I used syndaemon to enforce a typebreak after keypresses. With this I am able to type and not have a flying cursor everywhere :) .

Udev seems picky about using variables and “if” statements and such. So the script is basic:

#!/bin/bash
synclient TouchpadOff=0 MaxTapTime=0;
syndaemon -i 1 -d

When now the mouse is inserted the touchpad is deactivated and activated once more when the mouse is unplugged.

Entry Filed under: Linux. .

3 Comments Add your own

  • 1. matthias Schmutz  |  February 21, 2008 at 11:07 am

    hi how can I use this for changing the keyboardlayout if I plug a usb keyboard in?

  • 2. Dirk Gently  |  February 21, 2008 at 7:25 pm

    matthias, I DO believe this can be done, I haven’t though ever looked into anything about switching keyboard layout on the fly. Hold on a minute, its possible I have. I can say that there is a good guide here on setting up a simple udev event that can detect your hardware.

    http://gentoo-wiki.com/HOWTO_Customizing_UDEV#A_Simple_Method_For_Writing_A_USB_UDEV_Rule_With_lsusb

    As for the, ok found it. The command to type is setxkbmap as in

    setxkbmap dvorak

    Run this in association with the udev command to get a udev event. Udev will also need to be restarted to it can recognize the changes. The wiki tells what needs to be done to do that.

  • 3. Michael  |  June 1, 2008 at 10:53 am

    This works perfectly and is exactly what I was looking for. Thanks for doing the careful work and for your generosity in sharing it.

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Welcome to Tidbits.

Thanks for visiting. Helpful Linux Tidbits is a place for common bits of Linux knowledge and error fixes. Linux is an operating system that is growing at a fantastic rate and is exciting to be a part of - everyone can contribute to it. For the time being my posting will be limited as I try to find means to a new computer, unfortunately this may not be until October or November 2008.

I Enjoy the visit. Comments very very welcome.

Top Posts

Links

Subscribe

Atom Rss2

Creative Commons License