禁用笔记本键盘脚本

前言

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

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状态并切换,然后询问你是否立刻重启以生效.使用的时候只需要双击脚本即可.

相关推荐
xsc-xyc13 天前
用 Tailscale + Syncthing 实现手机、电脑与 NAS 的跨网络文件同步
linux·网络·网络安全·智能手机·电脑
集芯微电科技有限公司13 天前
四通道2A输出集成功率电感降压模块专为紧凑型方案设计
人工智能·单片机·嵌入式硬件·生成对抗网络·计算机外设
Digitally13 天前
如何快速将文件从电脑传输到平板电脑
stm32·嵌入式硬件·电脑
lichong95113 天前
让AI自己用电脑!Cua:后台操作鼠标键盘,Mac/Windows/Linux全支持
人工智能·macos·ai·计算机外设·agent·提示词
Saniffer_SH14 天前
【高清视频】Gen6 服务器还没到,Gen6 SSD 怎么测?Emily 现场演示三种测试环境
人工智能·驱动开发·测试工具·缓存·fpga开发·计算机外设·压力测试
阿泽·黑核14 天前
05 keyflow 扩展设计方案:矩阵键盘/组合键/事件队列/中断驱动
线性代数·矩阵·计算机外设·嵌入式·agent·vibe coding
想你依然心痛14 天前
手机远程控制电脑教程:安卓iOS远程桌面推荐、免费工具配置与远程办公技巧
android·智能手机·电脑
王小王-12314 天前
基于电脑硬件市场数据分析与可视化系统
数据库·数据分析·django·sqlite·电脑·电脑硬件数据·电脑硬件市场分析
老高学长14 天前
企业如何对局域网电脑进行监控?五个局域网电脑实时监控的方法分享,全方位监控电脑
网络·安全·电脑
科技每日热闻14 天前
618 AI显示器选购指南!爱攻AGON AI定制芯片电竞显示器AG277UX,适合哪些玩家?
人工智能·科技·游戏·计算机外设