1

I've been messing around with VT100 escape sequences on Windows 10. I know that this code:

@ECHO OFF
FOR /F %%A in ('ECHO prompt $E^| cmd') DO SET "ESC=%%A"
<NUL SET /P "=%ESC%[4;6HBye"

Will set the cursor position to 4,6 and display "Bye" starting from that position. My question is, is there any way to check what character is on a specific cursor location? As in, if I ask what's on cursor position 4,6, it'll tell me the letter "B"?

I've tried using a for command, kinda like this

FOR /F "delims=" %%A in ('<NUL SET /P "=%ESC%[4;6HBye"') DO (
    echo %%A
)

But it doesn't really work. Does anyone have a solution? Thank you.

LardPies
  • 95
  • 7
  • 1
    As per Microsoft's list of [Console Virtual Terminal Sequences](https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences) and [Appendix B of the VT100 User Manual](https://vt100.net/docs/tp83/appendixb.html), there is no such VT100 sequence. – SomethingDark Oct 21 '18 at 04:07
  • Not only can it not be done, but even if it could, there would be no way to capture the result without disturbing the screen content. See the Q&A at [Windows 10 console VT-100 escape sequences](https://stackoverflow.com/q/38237304/1012053) – dbenham Oct 21 '18 at 19:42

1 Answers1

3

You can not do that via VT100 escape sequences nor via a Batch command alone; however, you can do it using a different tool or language. For example, using PowerShell:

@echo off
setlocal

for /F "delims=" %%a in ('"PowerShell $console=$Host.UI.RawUI; $curPos=$console.CursorPosition; $rect=new-object System.Management.Automation.Host.Rectangle $curPos.X,$curPos.Y,$curPos.X,$curPos.Y; $BufCellArray=$console.GetBufferContents($rect); Write-Host $BufCellArray[0,0].Character;"') do set "char=%%a"
echo Char at cursor: "%char%"
Aacini
  • 65,180
  • 12
  • 72
  • 108