Detect/Correct Window size

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

Detect/Correct Window size

#1 Post by IcarusLives » 12 Jun 2024 13:54

Hello, I just want to see if anyone here can help me understand something.

When parsing MODE, why will it detect when the window is enlarged, but when I shrink the window, it does not seem to realize it?

I explicitly clear the temporary test values twid,thei(test wid test hei), yet it just.. does not see it? Can someone please help? Thanks :D

Code: Select all

@echo off & setlocal enableDelayedExpansion

if "%~1" neq "" goto :%~1

del /f /q "%temp%\%~n0_signal.txt"

set /a "wid=width=80"
set /a "hei=height=60"

mode %wid%,%hei%

"%~F0" Controller >"%temp%\%~n0_signal.txt" | "%~f0" windowFixer |"%~F0" Main <"%temp%\%~n0_signal.txt"
exit

:Main
	for /l %%# in () do (
		
		if defined key set "lastKey=!key!"
		set "key=" & set /p "key="
		
		echo !time! - last key: !lastKey! - Key: !key!

	)
exit



:Controller
	for /l %%# in () do for /f "tokens=*" %%i in ('choice /c:wasd /n') do echo=%%~i
exit



:windowFixer
	for /l %%# in () do (
		set "twid=
		set "thei="
		set /a windowSizeError=0"
		for /f "skip=2 tokens=2" %%a in ('mode') do if not defined thei (set /a "thei=%%a") else if not defined twid set /a "twid=%%a"
		REM title !twid! !thei!
		
		title if !twid! neq %wid% set /a "windowSizeError+=1"
		
		if !twid! neq %wid% set /a "windowSizeError+=1"
		if !thei! neq %hei% set /a "windowSizeError+=1"
		if !windowSizeError! gtr 0 (
			mode %wid%,%hei%
		)
	)
exit

IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

Re: Detect/Correct Window size

#2 Post by IcarusLives » 13 Jun 2024 05:50

I withdraw my question. Please close. Sorry, and thank you.

Post Reply