禁用笔记本键盘脚本

前言

在办公室时,笔记本拓展出两个外接显示器,笔记本放置在正前方显示器的下面时,没有空间放置我的机械键盘.只能把机械键盘放置在笔记本键盘上,出差时又需要使用笔记本自带的键盘;于是有了今天的这个脚本,用于快速开启与禁用笔记本脚本

bash 复制代码
@echo off
:: Check administrator privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
    echo Requesting administrator privileges...
    powershell -Command "Start-Process cmd -ArgumentList '/c %~0' -Verb RunAs"
    goto :eof
)

echo ========================================
echo    PS/2 Driver Auto Toggle Script
echo ========================================
echo.

:: Check current i8042prt service status
echo Checking current PS/2 driver status...
for /f "tokens=4" %%a in ('sc qc i8042prt ^| findstr "START_TYPE"') do (
    set start_type=%%a
)

echo Raw start type: %start_type%
echo.

:: Convert start type to human readable (support both numeric and text)
if "%start_type%"=="2" (
    set current_state=ENABLED
) else if "%start_type%"=="3" (
    set current_state=DEMAND_START
) else if "%start_type%"=="4" (
    set current_state=DISABLED
) else if "%start_type%"=="AUTO_START" (
    set current_state=ENABLED
) else if "%start_type%"=="DEMAND_START" (
    set current_state=DEMAND_START
) else if "%start_type%"=="DISABLED" (
    set current_state=DISABLED
) else (
    echo [ERROR] Unknown start type: %start_type%
    echo Known types: 2/AUTO_START=Auto, 3/DEMAND_START=Demand, 4/DISABLED=Disabled
    pause
    exit /b 1
)

echo Current PS/2 driver state: %current_state%
echo.

:: Set the appropriate action based on current state
if "%current_state%"=="ENABLED" (
    echo PS/2 driver is currently ENABLED
    echo Switching to DISABLED state...
    sc config i8042prt start= disabled
    set new_state=DISABLED
    goto :check_result
) else if "%current_state%"=="DISABLED" (
    echo PS/2 driver is currently DISABLED
    echo Switching to ENABLED state...
    sc config i8042prt start= auto
    set new_state=ENABLED
    goto :check_result
) else if "%current_state%"=="DEMAND_START" (
    echo PS/2 driver is currently DEMAND_START (Manual)
    echo Switching to ENABLED state...
    sc config i8042prt start= auto
    set new_state=ENABLED
    goto :check_result
)

:check_result
if %errorlevel% equ 0 (
    echo.
    echo [SUCCESS] PS/2 driver is now %new_state%
    echo [NOTE] Restart required to take effect
    echo.
    choice /C YN /M "Restart computer now (Y/N)?"
    if errorlevel 2 (
        echo Please remember to restart computer manually
    ) else (
        shutdown /r /t 5
        echo Computer will restart in 5 seconds...
    )
) else (
    echo.
    echo [ERROR] Operation failed, error code: %errorlevel%
    echo Please check if the service name is correct
)

echo.
pause

功能很简单,就是自动切换管理员模式,然后识别你的i8042prt状态并切换,然后询问你是否立刻重启以生效.使用的时候只需要双击脚本即可.

相关推荐
Giser板栗糖1 天前
发现笔记本电脑的触摸板没反应,怎么修复
经验分享·电脑
袖手蹲1 天前
Arduino UNO Q 从 Arduino Cloud 远程控制闪烁 LED
人工智能·单片机·嵌入式硬件·电脑
Digitally1 天前
如何在没有电脑的情况下备份 iPhone
ios·电脑·iphone
TESmart碲视1 天前
如何判断您的电脑是否支持MST多流传输技术?
电脑
小邋遢2.01 天前
笔记本电脑触摸板无反应
电脑·windos
uuleaf1 天前
26键打字训练小游戏:键盘练习游戏合集
游戏·计算机外设·编程打字
我送炭你添花1 天前
Pelco KBD300A 模拟器:01.Pelco 协议前世今生 & KBD300A 键盘基础解析
网络·python·计算机外设·pyqt
云飞云共享云桌面2 天前
告别传统电脑——智能装备工厂采用共享云桌面方案实现降本增效
运维·服务器·网络·人工智能·电脑
滴答滴答嗒嗒滴2 天前
Windows无法识别SD卡?SD卡刷这个镜像之后,用读卡器插电脑识别不到了
linux·ubuntu·电脑
ezeroyoung2 天前
Flutter HarmonyOS 键盘高度监听插件开发指南
flutter·计算机外设·harmonyos