yoav sarfaty
yoav sarfaty

Reputation: 43

Sending keyboard input with batch commands

we want our .bat file to send the "Enter" key every second. Is it possible? If so, how are we supposed to do that?

Will %SendKeys% {ENTER} work?

Our code currently:

@echo off
cls
color 0a
:loop
%SendKeys% {ENTER}
timeout /t 1 /nobreak >nul
goto :loop

Upvotes: 0

Views: 38508

Answers (2)

Sam Denty
Sam Denty

Reputation: 4085

It is not possible to send keys in batch files without using a third party utility or VBScript. Here is a hybrid VBScript-batch file that sends the Enter key every 1 second(s) continuously.

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

@echo off
    set SendKeys=CScript //nologo //E:JScript "%~F0"
    cls
    color 0a
    :loop
        %SendKeys% "{ENTER}"
        timeout /t 1 /nobreak >nul
    goto :loop

@end

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

NOTE: To change the keys inputted simply change the {enter} value.

Upvotes: 3

HackR_360
HackR_360

Reputation: 202

first download nircmd from here: http://nircmd.nirsoft.net/
create a batch file in the same directory where nircmd is and type:

@echo off
:loop
nircmd sendkeypress enter
timeout /t 1 /nobreak >nul
goto :loop

Upvotes: 1

Related Questions