本文共 2898 字,大约阅读时间需要 9 分钟。
Disable touchpad using keyboard shortcut
Working on a laptop can be extremely annoying when you accidentally hit the touchpad with your fingers. Here’s an easy fix to disable/enable the touchpad using a keyboard shortcut (like Ctrl - Alt - M). Step 1 Find the xinput device id of your touchpad This is how I found mine. fazle@thinkpad:~$ xinput ⎡ 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)] ↳ Truevision HD id=9 [slave keyboard (3)] ↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)] ↳ WMI hotkeys id=12 [slave keyboard (3)] fazle@thinkpad:~$ From the list I can easily see the id I am looking for is 11. If you are not sure, try this fazle@thinkpad:~$ xinput test 11 motion a[1]=2919 motion a[1]=2916 motion a[1]=2914 motion a[1]=2913 motion a[1]=2911 motion a[0]=2153 a[1]=2900 motion a[0]=2146 a[1]=2894 motion a[1]=2891 motion a[0]=2145 a[1]=2885 motion a[0]=2144 a[1]=2876 motion a[0]=2142 motion a[0]=2141 motion a[0]=2140 a[1]=2874 motion a[1]=2867 motion a[0]=2140 motion a[0]=2137 a[1]=2860 motion a[1]=2864 motion a[0]=2160 a[1]=2889 Run the command and swipe your finger on the touchpad. If you have the correct id, you would get those numbers. So we found the id for the touchpad which is 11 for my laptop. Step 2 Create the bash script Save the file somewhere in your path. Like /usr/local/bin/disable-touchpad.sh Also, don’t forget to change the TOUCHPADID#!/bin/bash## Purpose: Toggle synaptic touchpad on/off# Author: Fazle Arefin# Reference: http://ubuntuforums.org/showthread.php?t=1536305#TOUCHPADID=11 # change this idSYNSTATE=$(xinput list-props "$TOUCHPADID" | grep "Device Enabled" | grep -Eo '.$')if [ $SYNSTATE = 0 ]; then xinput set-prop "$TOUCHPADID" "Device Enabled" 1else xinput set-prop "$TOUCHPADID" "Device Enabled" 0fi
Make sure it is executable by you
chmod 755 /usr/local/bin/disable-touchpad.sh Step 3 Setup a keyboard shortcut Go to your Settings > Keyboard > Shortcuts using the GUI. In custom shortcuts point to /usr/local/bin/disable-touchpad.sh and setup the keyboard shortcut. I use Ctrl- Alt - Shift-T to enable/disable the touchpad.update on 14, Oct, 18
Just found the touchpadid changes dynamically every time I start up my computer, so I cannot set it as a fixed value, instead, I found it out by myself.
TOUCHPADID=$(xinput | grep "Touchpad" | grep -Po 'id=\K[0-9]+')SYNSTATE=$(xinput list-props "$TOUCHPADID" | grep "Device Enabled" | grep -Eo '.$')if [ $SYNSTATE = 0 ]; then xinput set-prop "$TOUCHPADID" "Device Enabled" 1else xinput set-prop "$TOUCHPADID" "Device Enabled" 0fi
转载地址:http://gaxdi.baihongyu.com/