Touchpad driving me crazy

On my Lenovo G780, running Mate 16.04, the touchpad is killing me. I have a USB mouse I use instead. At https://askubuntu.com/questions/438179/how-can-i-toggle-the-touchpad-depending-on-whether-a-mouse-is-connected/438220#438220 I found a way to supposedly disable the touchpad if it finds a USB mouse.

#!/usr/bin/env bash

## Get the touchpad id. The -P means perl regular expressions (for \K)
## the -i makes it case insensitive (better portability) and the -o
## means print only the matched portion. The \K discards anything matched
## before it so this command will print the numeric id only.
TID=$(xinput list | grep -iPo 'touchpad.*id=\K\d+')

## Run every second
while :
do
    ## Disable the touchpad if there is a mouse connected
    ## and enable it if there is none.
    xinput list | grep -iq mouse &&  xinput disable "$TID" || xinput enable "$TID"
    ## wait one second to avoind spamming your CPU
    sleep 1
done

“Now, save the script as ~/touchpad.sh, make it executable (chmod +x ~/touchpad.sh) and add it to your GUI session startup programs.”

I accomplished the three steps above, rebooted and the Touchpad is still active. I tried just running the script, but that has no effect either.

I’m now officially lost and need help. Any body have a clue?

Thanks, Fred

As an alternative thought — what about 2 hot keys, one for on, one for off. Or one hot key that just toggles it on and off.

Turning it off and then having the mouse battery die or croak is not a viable option, IMO.

Thanks, Fred

After more looking, at the manual for the computer, :frowning: Fn F6 toggles my Touchpad on and off.

This works for me.

1 Like

Ahh yup! I went through the same tortured process to then after learning to live in torment stumbled upon the simple hardware fix. For me it was staring at my keyboard looking for something else and … hmmmm wonder what THAT button’s for.

Fred, I tried several scripts that just did not work. Then, this morning, I searched the forum and found this post -

Unfortunately, he posted in screenshots. I took the liberty of transcribing the touchpadonoff script. It works but I suppose that a function key switch is really a lot easier.

#!/bin/bash
# TouchOnOff, version 1.0, December 2017, Author: GFP
# Adaptation of the KbOnOff bash script

Icon=/usr/share/icons/gnome/256x256/status/user-available.png  # <path to the touchpad icon on>
Icoff=/usr/share/icons/gnome/256x256/status/user-busy.png      # <path to the touchpad icon off>

# because the value of "id" can change on xinput, the code does not rely on hardcoded id/master numbers
mainkey=`xinput list | grep "AlpsPS/2 ALPS DualPoint TouchPad"` # find your touchpad by using xinput
# above works if touchpad is enabled: "↳ AlpsPS/2 ALPS DualPoint TouchPad id=xx	[slave  pointer (y)]", or
# disabled: "∼ AlpsPS/2 ALPS DualPoint TouchPad id=xx [floating slave]"
idvar=`echo ${mainkey#*=}`  # return "xx [slave pointer (y)]" or "xx [floating slave]" where xx=id number
idvar=`echo ${idvar%% *}`   # return xx
#
touchvar=`echo ${mainkey#*[}`   # return "slave pointer (y)]" or "floating slave]"
touchvar=`echo ${touchvar%% *}` # return "slave" or "floating"
if [ $touchvar = "floating" ]   # touchpad currently disabled
	then
		mastkey=`xinput list | grep "Virtual core pointer"`  # grab the master pointing string
		# return "[ Virtual core pointer  id=x   [master pointer  (y)]]"
		mastkey=`echo ${mastkey#*"pointer  ("}`  # return "y)]"
		mastkey=`echo ${mastkey%)*}`             # return "y"
		mastkey=$[$mastkey-1]                    # "y"-1 is the laptop touchpad master id
		notify-send -i $Icon "Enabling touchpad..." \ "ON - Touchpad connected !"
		echo "Enabling touchpad ..."
		xinput reattach $idvar $mastkey
	elif [ $touchvar = "slave" ]  # touchpad currently enabled
		then
			notify-send -i $Icoff "Disabling Touchpad" \ "OFF - Touchpad disconnected"
			echo "Disabling touchpad ..."
			xinput float $idvar
fi

This is a handy script. Thanks @guillef.

1 Like

I don't even begin to understand that script, plus your conclusion is correct. A 2 button click for this old guy works just fine.

Thank for trying, but I am almost 90% trained as of today to click my BIC :slight_smile:

Cheers, Fred