2

I had previously posted instructions for this that worked for Freya on:

How to automatically disable touchpad when USB mouse connected

Given that Loki uses libinput intead of synaptic drivers, that no longer works. I have revised the instructions to disable the touchpad using the xinput command, so it appears to work with libinput or synaptic. The following instructions work in Loki and should work in Freya as well.

Jay

1

Or the far easier method:

Install, and run, Dconf-editor.

Then do the following: Search (ctrl-f)

touchpad

When you get to the key org.gnome.desktop.peripherals.touchpad

Then look in the right pane, and you will find the key send-events

Change the value of the key by clicking, and choosing disabled on external mouse

And that's it.enter image description here

  • LOL! So much easier. I'm going to try it tonight! Thanks so much. – Jason Gambrel Oct 21 '16 at 16:57
  • Works beautifully for me. Thanks for a much simpler solution. I feel like I just spent hours reinventing the wheel! – Jason Gambrel Oct 21 '16 at 19:12
  • No problem. I feel like those sorts of answers, while indeed correct, are what I was used to doing fifteen years ago, and this is a much more simple and elegant solution. – Callista Graves Oct 26 '16 at 19:47
1

Here is my solution for disabling the touchpad in elementary OS when attaching a USB mouse.

Here are some websites for reference:

https://bbs.archlinux.org/viewtopic.php?id=188918

https://bbs.archlinux.org/viewtopic.php?id=170396

As well as the arch wiki on Synaptics touchpad.

Open a terminal by pressing the key combination: Super + T or by opening it from the Applications menu

Get a list of input devices by typing

xinput

Note what your touchpad device is called and write it down exactly. For example, mine is called: SynPS/2 Synaptics TouchPad

Enter the following at the prompt to open Scratch as root:

sudo scratch-text-editor

Enter your password when asked.

Create a new file.

Paste the following into the new file:

SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="add", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/$USERNAME$/.Xauthority", RUN+="/bin/sh -c 'xinput disable SynPS/2\ Synaptics\ TouchPad'"
SUBSYSTEM=="input", KERNEL=="mouse[0-9]*", ACTION=="remove", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/$USERNAME$/.Xauthority", RUN+="/bin/sh -c 'xinput enable SynPS/2\ Synaptics\ TouchPad'"

* Replace $USERNAME$ in these 2 lines with your actual username. *

* Replace SynPS/2\ Synaptics\ TouchPad with the name of your touchpad placing backslashes (\) in front of each space in the name *

Click the save button

Click “Other Locations” in the left hand column of the dialogue box, then "Computer" in the right column.

Navigate to the /etc/udev/rules.d folder

Type the name “01-touchpad.rules” as the name of the file and click Save

Close the file

This alone should enable and disable the touchpad when attaching or detaching a USB mouse. This will not disable the touchpad at system startup if a USB mouse is attached. To do this you can do the following:

Open a terminal Enter the following at the prompt to open Scratch as root:

sudo scratch-text-editor

Enter your password when asked.

Create a new file and paste the following into it:

#!/bin/bash
lista=`xinput list | grep -i 'mouse'`
listb=`xinput list | grep -i 'transceiver' | grep -i 'pointer'`
listc=`xinput list | grep -i 'receiver' | grep -i 'pointer'`

if [ ${#lista} -eq 0 ] && [ ${#listb} -eq 0 ] && [ ${#listc} -eq 0 ]; then
    exec `xinput enable SynPS/2\ Synaptics\ TouchPad`
    notify-send "No USB Mouse Detected" "Your Touchpad is Active"
else
    exec `xinput disable SynPS/2\ Synaptics\ TouchPad`
    notify-send "USB Mouse Detected" "Your Touchpad is Disabled"
fi

* Again replace SynPS/2\ Synaptics\ TouchPad with the name of your touchpad placing backslashes (\) in front of each space in the name *

Click the Save button.

Click “Other Locations” in the left hand column of the dialogue box, then "Computer" in the right column.

Type the name "mouse_detect.sh" for the filename and click Save.

Open the "Files" application as an Administrator. If it is on your Plank, right click to find this option. If it is not, then open "Files" from the application menu and right-click the icon on Plank when it opens to find the option. Enter your password when asked.

Click "File System" in the left column and navigate to /usr/local/bin. Your file "mouse_detect.sh" should be present. Right click on this file and select "Properties" Click on the "More" button and then click on each of the "Execute" buttons to ensure they are all highlighted.

Close Files.

Now we need to create an autostart entry Open "System Settings" and click "Applications" Click "Startup" and click the "+" button in the lower left hand corner. When the box opens up type "/usr/local/bin/mouse_detect.sh" in the lower box where it asks you to type a custom command.

Open "Files" and press CTRL-H to display hidden files and press Home in the left hand column Navigate to the ~/.config/autostart

You should see a file like "Custom Command", open this in "Scratch" by right clicking and selecting Open With. (select Other Application if necessary) You should see a line that says Exec=/usr/local/bin/mouse_detect.sh if you are in the right file.

Add the following line line to the file:

X-GNOME-Autostart-Delay=30

You can also enter a custom name for the desktop file in the "Name" field and a custom comment in the "Comment" field.
Note: I had to remove the [en_CA] from my Name[en_CA] field for the name change to be visible in "Files". You might have to do the same if you live outside the US.

If you go back to your startup applications, your custom Name and Comment should be visible and you can enable or disable the autorun of this script on startup by clicking on the toggle to the right of it.

That should do it. If the startup script detects other wireless devices as a mouse and disables your touchpad when it shouldn't you can try changing the contents of the mouse_detect.sh file to:

#!/bin/bash
lista=`xinput list | grep -i 'mouse'`

if [ ${#lista} -eq 0 ]; then
    exec `xinput enable SynPS/2\ Synaptics\ TouchPad`
    notify-send "No USB Mouse Detected" "Your Touchpad is Active"
else
    exec `xinput disable SynPS/2\ Synaptics\ TouchPad`
    notify-send "USB Mouse Detected" "Your Touchpad is Disabled"

fi

* Replace SynPS/2\ Synaptics\ TouchPad with the name of your touchpad placing backslashes (\) in front of each space in the name *

This has less chance of detecting wireless mice though, so only use it if the first one does not work for you.

Jay

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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