You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

批处理脚本中实现重复按键或模拟Ctrl+A的方法咨询

解决方案

方法一:用Ctrl+A全选后删除(推荐)

SendKeys支持组合键语法,^A对应Ctrl+A(^是Ctrl键的标识),全选字段内容后按一次{DELETE}或{BACKSPACE}就能一键清空,比多次发送退格键高效得多。

修改后的完整代码:

@if (@CodeSection == @Batch) @then
@echo off
setlocal enabledelayedexpansion
set SendKeys=CScript //nologo //E:JScript "%~F0"
START msedge "https://fams.nabard.org:48443/PanaceaFAMS/login.faces"

timeout /t 6
!SendKeys! "^A{DELETE}"
!SendKeys! "43569"
!SendKeys! "{TAB}"  
@end
// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

方法二:批量重复发送BACKSPACE

如果偏好保留退格逻辑,可直接在SendKeys参数中指定重复次数,格式为{BACKSPACE N}(N为重复次数,按键与数字间加空格),一次调用即可完成多次退格操作。

修改后的完整代码:

@if (@CodeSection == @Batch) @then
@echo off
setlocal enabledelayedexpansion
set SendKeys=CScript //nologo //E:JScript "%~F0"
START msedge "https://fams.nabard.org:48443/PanaceaFAMS/login.faces"

timeout /t 6
!SendKeys! "{BACKSPACE 9}"
!SendKeys! "43569"
!SendKeys! "{TAB}"  
@end
// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

补充SendKeys语法要点

  • ^代表Ctrl键,+代表Shift键,%代表Alt键
  • 按键后紧跟数字可实现重复发送,比如{TAB 3}就是连续按3次Tab
  • 组合键直接连写即可,比如^%S对应Ctrl+Alt+S

内容的提问来源于stack exchange,提问作者Gdfhj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 14:36:53