Page 1 of 1
Key Press through Batch File
Posted: 19 Jul 2013 01:35
by Niraj
Hi,
Want to access some key board Button through Batch script.
Example: Suppose open notepad through script,and Want to access
Ctrl+S : For saving the file
Ctrl+P : For Print that file
or some some simple key opertion.
like Write some already define content.
Thanks in Advance
Regards,
Niraj
Re: Key Press through Batch File
Posted: 19 Jul 2013 03:49
by foxidrive
The program AutoIt is a good tool for pressing buttons in an application.
Re: Key Press through Batch File
Posted: 19 Jul 2013 05:21
by npocmaka_
You can use wscript sendkeys function.and AppActivate to send the keys to an application:
http://social.technet.microsoft.com/wik ... ethod.aspxhere's a sendkeys.bat:
Code: Select all
@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment
@echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b 0
***jscript part****/
var WshShell = WScript.CreateObject("WScript.Shell");
var args=WScript.Arguments;
WshShell.AppActivate(args.Item(0));
//sleep(1500)
WshShell.SendKeys(args.Item(1));
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
/*http://social.technet.microsoft.com/wiki/contents/articles/5169.vbscript-sendkeys-method.aspx*/
Does not check command line arguments but this can be added easy.First argument is the image name of the .exe you want to send keys to and the second is are the keys:
Code: Select all
sendkeys.bat notepad {space}{tab}{enter}blabla