Send "Backspace" Key in Batch
Moderator: DosItHelp
-
- Posts: 82
- Joined: 24 Apr 2011 19:20
Send "Backspace" Key in Batch
Hello,
Is there a way to send the "Backspace" key in a batch program? I know it would be easier to use a VBScript file and incorporate it into the batch program, but I'm not entirely sure how to do that and I would like for the program to stay one file. Thanks for any help.
Is there a way to send the "Backspace" key in a batch program? I know it would be easier to use a VBScript file and incorporate it into the batch program, but I'm not entirely sure how to do that and I would like for the program to stay one file. Thanks for any help.
Re: Send "Backspace" Key in Batch
'
Untested !
Code: Select all
@echo off
setlocal EnableDelayedExpansion
::--------------------------------------------------------------------------------------------------------------------------
set "$Defines=$BS" &set "$Details=Create $ESC Ascii-0x1B-27, Expansion insensitive"
::
::(
for /f "delims=#" %%a in (
'"prompt #$H# &echo on &for %%b in (1) do rem"'
) do (
set "%$Defines%=%%a"
set "%$Defines%=!$BS:~0,1!"
)
::
echo.This %$BS%Works
::)
::--------------------------------------------------------------------------------------------------------------------------
-
- Posts: 82
- Joined: 24 Apr 2011 19:20
Re: Send "Backspace" Key in Batch
Thanks Ed! It works perfectly!
Re: Send "Backspace" Key in Batch
Ed's code can be simplified. No need for delayed expansion, # symbols, DELIMS option, ECHO ON, or substring.
Also, the comment in Ed's code is misleading, obviously a carryover from some other code.
Here is a simplified version with corrected comment, preserving Ed's unique style
Below is effectively the same code, as I like to write it.
Dave Benham
Also, the comment in Ed's code is misleading, obviously a carryover from some other code.
Here is a simplified version with corrected comment, preserving Ed's unique style
Code: Select all
@echo off
setlocal
::--------------------------------------------------------------------------------------------------------------------------
set "$Defines=$BS" &set "$Details=Create $BS Ascii-0x08-008, Expansion insensitive"
::
::(
for /f %%a in (
'"prompt $H&for %%b in (1) do rem"'
) do (
set "%$Defines%=%%a"
)
::
echo.This %$BS%Works
::)
::--------------------------------------------------------------------------------------------------------------------------
Below is effectively the same code, as I like to write it.
Code: Select all
@echo off
setlocal
:: Define BS to contain a backspace
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
echo.This %BS%Works
Dave Benham
Re: Send "Backspace" Key in Batch
'
My implementation produces 08 20 08, somewhere you pointed out to strip at 0,1.
Wasn't sure about the 'echo on' requirement, looked into cmd /?.
Couldn't find any evidence that 'echo' can be disabled from registry so it probably safe if left out.
You beat me, or was it jeb
My implementation produces 08 20 08, somewhere you pointed out to strip at 0,1.
Wasn't sure about the 'echo on' requirement, looked into cmd /?.
Couldn't find any evidence that 'echo' can be disabled from registry so it probably safe if left out.
You beat me, or was it jeb
-
- Posts: 76
- Joined: 21 Dec 2011 14:21
Re: Send "Backspace" Key in Batch
dbenham wrote:Ed's code can be simplified. No need for delayed expansion, # symbols, DELIMS option, ECHO ON, or substring.
Below is effectively the same code, as I like to write it.Code: Select all
@echo off
setlocal
:: Define BS to contain a backspace
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
echo.This %BS%Works
Dave Benham
dave, can you explain a noobish question? why the need for the for %%b loop?
i knowthat Alt+008 does a backspace, is there a way to use that functionality in a macro?
thanks
tt
Re: Send "Backspace" Key in Batch
The FOR IN() clause commands are executed by a new CMD.EXE process. They are parsed all at once as a single block of commands.
ECHO is initially off when the commands are executed. We need ECHO ON to get the prompt output for the REM command.
The code block turns ECHO ON, but the change in state is not recognized within the already parsed block of commnds - the entire block uses the ECHO STATE that existed when the block was entered. The one exception is the FOR DO clause uses the current ECHO state that exists at the beginning of each iteration. The extra FOR statement is the only way to get the REM statement to be echoed.
Dave Benham
ECHO is initially off when the commands are executed. We need ECHO ON to get the prompt output for the REM command.
The code block turns ECHO ON, but the change in state is not recognized within the already parsed block of commnds - the entire block uses the ECHO STATE that existed when the block was entered. The one exception is the FOR DO clause uses the current ECHO state that exists at the beginning of each iteration. The extra FOR statement is the only way to get the REM statement to be echoed.
Dave Benham
-
- Posts: 76
- Joined: 21 Dec 2011 14:21
Re: Send "Backspace" Key in Batch
dbenham wrote:The FOR IN() clause commands are executed by a new CMD.EXE process. They are parsed all at once as a single block of commands.
ECHO is initially off when the commands are executed. We need ECHO ON to get the prompt output for the REM command.
The code block turns ECHO ON, but the change in state is not recognized within the already parsed block of commnds - the entire block uses the ECHO STATE that existed when the block was entered. The one exception is the FOR DO clause uses the current ECHO state that exists at the beginning of each iteration. The extra FOR statement is the only way to get the REM statement to be echoed.
Dave Benham
wunderbar! that was a great explanation...
now that i know...
thanks again Dave