使用批处理文件按键盘键 [英] Press Keyboard keys using a batch file

查看:42
本文介绍了使用批处理文件按键盘键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个批处理文件,它可以自动按左箭头和右箭头键 n 次,中间有一些停顿.有人可以帮我解决这个问题吗?

I am trying to develop a batch file which can automatically press left arrow and right arrow key for n number of times with some pause in between. Could anybody please help me with this?

P.S:我尝试安装自动键盘软件,但由于我在工作,所以无法安装.我需要这个程序才能在我的办公室电脑上运行.

P.S: I tried installing auto keyboard software but I couldn't install them since I was at work. I need this program to work on my office PC.

推荐答案

哇!这意味着您必须学习不同的编程语言才能将两个键发送到键盘?有更简单的方法可以让您实现相同的目标.:-)

Wow! Mean this that you must learn a different programming language just to send two keys to the keyboard? There are simpler ways for you to achieve the same thing. :-)

下面的批处理文件是一个示例,它启动另一个程序(在本例中为 cmd.exe),向它发送一个命令,然后发送一个向上箭头键,这会导致恢复上次执行的命令.Batch 文件非常简单,易于理解,因此您可以根据需要对其进行修改.

The Batch file below is an example that start another program (cmd.exe in this case), send a command to it and then send an Up Arrow key, that cause to recover the last executed command. The Batch file is simple enough to be understand with no problems, so you may modify it to fit your needs.

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem Start the other program in the same Window
start "" /B cmd

%SendKeys% "echo off{ENTER}"

set /P "=Wait and send a command: " < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "echo Hello, world!{ENTER}"

set /P "=Wait and send an Up Arrow key: [" < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "{UP}"

set /P "=] Wait and send an Enter key:" < NUL
ping -n 5 -w 1 127.0.0.1 > NUL
%SendKeys% "{ENTER}"

%SendKeys% "exit{ENTER}"

goto :EOF


@end


// JScript section

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

有关 SendKeys 的键名列表,请参阅:http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx

For a list of key names for SendKeys, see: http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx

例如:

LEFT ARROW    {LEFT}
RIGHT ARROW   {RIGHT}

有关此解决方案的进一步说明,请参阅:GnuWin32 openssl s_client conn 到 WebSphere MQ 服务器未在 EOF 关闭,挂起

For a further explanation of this solution, see: GnuWin32 openssl s_client conn to WebSphere MQ server not closing at EOF, hangs

这篇关于使用批处理文件按键盘键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆