write a batch script to press “tab” and “Enter” ke

2019-08-12 18:54发布

I need to press "TAB" and "Enter" key using either a batch script or VB script.

OK, I'm writing the vb file in notepad. I run it by double clicking icon testVB.vbs in C:. This is what I have: testVB.vbs

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "test.bat"
WScript.Sleep 1000 
WshShell.SendKeys (TAB) //to tab from the cancel button to open button
WScript.Sleep 1000
WshShell.SendKeys "~"  //clicks open button

test.bat

@ECHO OFF
START  MSAccess "C:\path\file.mdb"

I want to open Access and the DB, but a pop up window appears which is what I'm trying to get around. After I figure that out I will need to figure out how to write code to import a .txt file to the DB.

The TAB is what is not working, I have tried {TAB}, "TAB", (TAB), and different combos. I get an error with the first one and the others have no action. The enter works though ("~").

1条回答
可以哭但决不认输i
2楼-- · 2019-08-12 19:40

Try this;

@if (@CodeSection == @Batch) @then
@echo off
CScript //nologo //E:JScript "%~F0"
goto :EOF
@end
WScript.Sleep (1000)
WScript.CreateObject("WScript.Shell").SendKeys("{TAB}");
WScript.Sleep (1000)
WScript.CreateObject("WScript.Shell").SendKeys("~");
查看更多
登录 后发表回答