15

I managed to install Ubuntu 16.04 on my asus ux501 vw, but some of my shortcut are not working. I'm not looking to fix them all, but just one : the shortcut which allow me to enable or disable touchpad, so i can write long documents with working about the touchpad.

I tried to find it on google but I got nothing.

Can someone explain me how to fix that please? Thanks !

21

I created this bash script from negusp's answer. It finds and toggles TouchPad device. You can configure a custom shortcut to it in system settings.

#!/bin/bash

read TPdevice <<< $( xinput | sed -nre '/TouchPad/s/.*id=([0-9]*).*/\1/p' )
state=$( xinput list-props "$TPdevice" | grep "Device Enabled" | grep -o "[01]$" )

if [ "$state" -eq '1' ];then
    xinput --disable "$TPdevice" && notify-send -i emblem-nowrite "Touchpad" "Disabled"
else
    xinput --enable "$TPdevice" && notify-send -i input-touchpad "Touchpad" "Enabled"
fi

I'm setting Ctrl+Shift+F9 for toggle touchpad enable and disable like this:

enter image description here

Edit: You may need to make your script to executable with command chmod +x filename or input /bin/bash /filepath to Command field of Custom shortcut window.

  • 2
    There's rarely a need to chain grep and sed. You can easily consolidate the two to sed -nre '/TouchPad/s/.*id=([0-9]*).*/\1/p'. – David Foerster Jan 22 '17 at 11:55
  • ubuntu's touchpad is so sensitive , I was struggling with everyday , this fixed it forever , thank you .. – aeid Apr 6 '17 at 19:43
  • I have a similar script but this one is cooler. +1 – WinEunuuchs2Unix Apr 11 '17 at 17:23
  • 3
    A small correction in script for Ubuntu 17.10 after getting error line 6: [: : integer expression expected unable to find device Change TouchPad to Touchpad – infotronika Nov 11 '17 at 9:35
  • 1
    Awesome answer! My only additions are to add zenity --info --text "Touchpad DISABLED" --timeout=2 and zenity --info --text "Touchpad ENABLED" --timeout=2 to your if and else blocks, respectively, to pop up a window which announces the new state then autocloses in 2 sec. – Gabriel Staples Apr 2 '18 at 18:44
10

You want shortcut, but you can easily put 2 scripts on the desktop and execute them.

First, go to terminal. Type xinput. Output Example:

⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=12   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ Laptop_Integrated_Webcam_1.3M             id=10   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=11   [slave  keyboard (3)]
    ↳ Dell WMI hotkeys 

Find the Touchpad. In this example, the touchpad is listed as id=12

Create the first script with this:

#!/bin/bash
xinput enable 12

Save it and name it touchpadenable.sh, and in terminal, mark it as executable with:

chmod +x touchpadenable.sh

Do the exact same thing again, but rename the file as touchpaddisable.sh (or whatever), and instead of

xinput enable 12

Use the command

xinput disable 12

Save, mark as executable, and you should be able to run the scripts from the desktop. Note: you may have to right-click the scripts, click properties, and allow it to be executed.

  • Hey thanks for the answer ! I will use something like this ! Just one thing do you think it would be possible if i make it on 1 script file so that i can use the same shortcut? – Thomas Nov 2 '16 at 13:47
  • @Thomas See this answer: askubuntu.com/questions/597395/… – negusp Nov 2 '16 at 13:57
4

You must to do like negusp's answer, first check your touch device, and will shows something like this:

~$ xinput
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ PixArt Dell MS116 USB Optical Mouse       id=10   [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=14   [slave  pointer  (2)]
⎜   ↳ DLLC6B2:00 06CB:75BF Touchpad             id=12   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Power Button                              id=8    [slave  keyboard (3)]
    ↳ Sleep Button                              id=9    [slave  keyboard (3)]
    ↳ Integrated_Webcam_HD                      id=11   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=13   [slave  keyboard (3)]
    ↳ Dell WMI hotkeys                          id=15   [slave  keyboard (3)]
    ↳ DELL Wireless hotkeys                     id=16   [slave  keyboard (3)]

In my case is the device with id=12, now create a bash script with name "toggle-touch" in you Desktop folder under a folder named "bin", would be "~/Desktop/bin" and copy next code, check the device variable is pointed to my touch id=12, fix it with your case:

#!/bin/bash

device=12
state=`xinput list-props "$device" | grep "Device Enabled" | grep -o "[01]$"`

if [ $state == '1' ];then
  xinput --disable $device
else
  xinput --enable $device
fi

Set to this script execution permission:

chmod 775 /Desktop/bin/toggle-touch

Finally you can add this path to the ".bashrc" from your home folder, just add this line to the end of file:

PATH=$PATH:~/Desktop/bin

update the path with:

. .bashrc

Then you can execute this script from any place, I hope this help.

1

Do like @Almas Dusal's answer, which does like @negusp's answer, except use my modified script instead:

read TPdevice <<< $( xinput | sed -nre '/TouchPad/s/.*id=([0-9]*).*/\1/p' )
state=$( xinput list-props "$TPdevice" | grep "Device Enabled" | grep -o "[01]$" )

if [ "$state" -eq '1' ];then
    xinput --disable "$TPdevice"
    zenity --info --text "Touchpad DISABLED" --timeout=2
else
    xinput --enable "$TPdevice"
    zenity --info --text "Touchpad ENABLED" --timeout=2
fi

Now, assign it a shortcut key of Ctrl + Alt + P (or whatever you choose [the 'P' stands for touch'P'ad in my case]). My addition to the script above is the zenity self-closing popup window part, which I describe more in my answer here (https://superuser.com/a/1310142/425838).

Now, when I use the shortcut above, I see this popup window, which auto-closes after 2 seconds:

enter image description here

And if I press it again I get this popup window, which auto-closes after 2 seconds:

enter image description here

Perfect!

As an added bonus, if you are a heavy mouse user, just add the command which calls your script above to your startup programs in Ubuntu so it runs and disables your track pad every time your computer starts up! I have this set so I can quit bumping the track pad with the base of my hand and deleting stuff accidentally all the time! Now, when my hand bumps the track pad, nothing happens because it's disabled. :)

Note: this all works great in Ubuntu 18.04 as well as older versions. I've tested it in Ubuntu 18.04 and Ubuntu 14.04. Here's a screenshot from the shortcut settings window in 18.04:

enter image description here

0

Leaving my script here (more or less the same as above). Works out of the box, no need for prior lookup of the device ID.

#!/bin/bash

function query_device_id {
    xinput list | grep -i touchpad | sed 's/.*id=\([0-9]*\).*/\1/g'
}

let device_id=$(query_device_id)

let state=$(xinput list-props $device_id | grep Enabled | awk '{print $4;}')

let new_state=$((1 - $state))

xinput set-prop $device_id "Device Enabled" $new_state
0

Create a shell script and paste below code in to it and name it touchPadDisable.sh

#!/bin/bash
temp=$(xinput | grep -i "Elantech Touchpad" | cut -d"=" -f 2 | cut -d"[" -f 1)
xinput disable $temp

Create another shell script and paste below code in to it and name it touchPadEnable.sh

#!/bin/bash
temp=$(xinput | grep -i "Elantech Touchpad" | cut -d"=" -f 2 | cut -d"[" -f 1)
xinput enable $temp

First script will disable touchpad and second one will enable touchpad.

You can add this script to custom shortcuts in keyboards.

0

In my Ubuntu 18.04 Almas Dusal's answer didn't work until I changed the 'p' to lower case in TouchPad in the following line of his code:

read TPdevice <<< $( xinput | sed -nre '/Touchpad/s/.*id=([0-9]*).*/\1/p' )

After that touchpad was succesfully disabled and enabled by the script but that was not reflected in the Mouse & Touchpad settings screen. I created the following new script which toggles the touchpad while updating the settings view.

#!/bin/bash

state=$( gsettings get org.gnome.desktop.peripherals.touchpad send-events )

if [ "$state" = "'enabled'" ];then
    gsettings set org.gnome.desktop.peripherals.touchpad send-events 'disabled' \
        && notify-send -i touchpad-disabled-symbolic "Touchpad" "Disabled"
else
    gsettings set org.gnome.desktop.peripherals.touchpad send-events 'enabled' \
        && notify-send -i input-touchpad-symbolic "Touchpad" "Enabled"
fi

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.