To achieve this we make use of xinput command.

The following script will do the job. Create a new file paste the following.

1
2
3
4
5
6
7
8
9
#!/bin/bash
if xinput list-props 12 | grep "Device Enabled (142):.*1" >/dev/null
then
  xinput disable 11
  notify-send -u low -i mouse "Trackpad disabled"
else
  xinput enable 11
  notify-send -u low -i mouse "Trackpad enabled"
fi

Run xinput list to find your device id:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=11   [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)]
    ↳ HP Webcam-50                              id=9    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=10   [slave  keyboard (3)]
    ↳ HP WMI hotkeys                            id=12   [slave  keyboard (3)]
    ↳ HP Wireless hotkeys                       id=13   [slave  keyboard (3)]

Then run xinput list-props 11 where 11 is the id of your touchpad. Look for the line:

Device Enabled (142): 1

And change line two of the script to match.

Also do not forget to make it executable. Also notify-send needs a notification server backend running in the background. I use dunst for this purpose.

You can assign some key/key combination to execute the script. I mapped this script to F4. This can be achieved by different methods, xmodmap being one of them.