本文目录导读:

我来介绍几种禁用触摸板的脚本方法,适用于不同操作系统:
Windows 系统
方法1:PowerShell 脚本
# 以管理员身份运行
Get-PnpDevice | Where-Object {$_.FriendlyName -like "*touchpad*" -or $_.FriendlyName -like "*触摸板*"} | Disable-PnpDevice -Confirm:$false
启用触摸板:
Get-PnpDevice | Where-Object {$_.FriendlyName -like "*touchpad*" -or $_.FriendlyName -like "*触摸板*"} | Enable-PnpDevice -Confirm:$false
方法2:设备管理器命令
:: 触摸板禁用脚本.bat @echo off :: 运行 devcon 工具(需要Windows Driver Kit) devcon disable *触摸板*
Linux 系统
方法1:使用 xinput(X11)
#!/bin/bash # 查找触摸板ID touchpad_id=$(xinput list | grep -i "touchpad\|触控板" | grep -oP 'id=\K[0-9]+' | head -1) # 禁用触摸板 xinput disable $touchpad_id
方法2:使用 libinput(Wayland)
#!/bin/bash # 列出所有输入设备 libinput list-devices # 禁用触摸板(需要找到设备名) gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled
macOS 系统
使用系统偏好设置命令
#!/bin/bash # 禁用触摸板 sudo defaults write com.apple.AppleMultitouchTrackpad TrackpadEnable -bool FALSE sudo defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadEnable -bool FALSE # 重新加载设置 sudo killall cfprefsd
通用脚本(跨平台 - Python)
#!/usr/bin/env python3
import platform
import subprocess
import sys
def disable_touchpad():
system = platform.system()
if system == "Windows":
# Windows PowerShell 命令
ps_command = """
Get-PnpDevice | Where-Object {$_.FriendlyName -like "*touchpad*"} |
Disable-PnpDevice -Confirm:$false
"""
subprocess.run(["powershell", "-Command", ps_command],
capture_output=True, shell=True)
elif system == "Linux":
# 尝试多种方法
try:
# 方法1: xinput
subprocess.run("xinput list", shell=True, check=True)
touchpad_id = subprocess.check_output(
"xinput list | grep -i touchpad | grep -oP 'id=\\K[0-9]+' | head -1",
shell=True, text=True
).strip()
if touchpad_id:
subprocess.run(f"xinput disable {touchpad_id}", shell=True)
except:
# 方法2: 使用 synclient
subprocess.run("synclient TouchpadOff=1", shell=True)
elif system == "Darwin": # macOS
subprocess.run("""
sudo defaults write com.apple.AppleMultitouchTrackpad TrackpadEnable -bool FALSE
sudo killall cfprefsd
""", shell=True)
else:
print(f"不支持的系统: {system}")
sys.exit(1)
print("触摸板已禁用")
def enable_touchpad():
system = platform.system()
if system == "Windows":
ps_command = """
Get-PnpDevice | Where-Object {$_.FriendlyName -like "*touchpad*"} |
Enable-PnpDevice -Confirm:$false
"""
subprocess.run(["powershell", "-Command", ps_command],
capture_output=True, shell=True)
elif system == "Linux":
try:
touchpad_id = subprocess.check_output(
"xinput list | grep -i touchpad | grep -oP 'id=\\K[0-9]+' | head -1",
shell=True, text=True
).strip()
if touchpad_id:
subprocess.run(f"xinput enable {touchpad_id}", shell=True)
except:
subprocess.run("synclient TouchpadOff=0", shell=True)
elif system == "Darwin":
subprocess.run("""
sudo defaults write com.apple.AppleMultitouchTrackpad TrackpadEnable -bool TRUE
sudo killall cfprefsd
""", shell=True)
print("触摸板已启用")
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "enable":
enable_touchpad()
else:
disable_touchpad()
使用说明
保存为脚本文件
- Windows: 保存为
disable_touchpad.bat或.ps1 - Linux/macOS: 保存为
disable_touchpad.sh,赋予执行权限:chmod +x disable_touchpad.sh ./disable_touchpad.sh
注意事项
- 管理员权限: 大多数操作需要以管理员/root身份运行
- 设备名差异: 不同品牌的触摸板名称可能不同,可能需要调整匹配规则
- 驱动兼容性: 某些专有驱动可能需要特殊的禁用方法
命令行快捷方式(Linux)
# 临时禁用(重启后恢复) alias disable-touchpad='xinput disable $(xinput list | grep -i touchpad | grep -oP "id=\K[0-9]+" | head -1)' # 添加到 ~/.bashrc 或 ~/.zshrc 永久生效
告诉我你的操作系统,我可以提供更具体的脚本!