Button functions via VT100, and Mouse.exe

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Button functions via VT100, and Mouse.exe

#1 Post by IcarusLives » 12 Aug 2019 08:50

Hello! I have been working on some functions that allow you to click the console with a 3rd party called Mouse.exe

MOUSE.EXE -> http://www.mediafire.com/file/96p9tqu4d500fli/bin.zip

Image

I thought this would be a fun project to limit user input. Overall I AM looking to improve this.

Any suggestions on making it faster, more appealing. Please let me know!

Hope you enjoy!

code

Code: Select all

@echo off & setlocal enableDelayedExpansion

call:importantStuff
call:extras
call:createToggle "RED  GRE  YEL  BLU  PUR" 1 2 5 12 3
call:createSlider 1 14 23 10 9 0 20
call:createButton 1 5 "Move Left "
call:createButton 15 5 "Move Right"
call:createButton 1 8 "Move  Up "
call:createButton 15 8 "Move Down"

:main
rem update the toggle box
call:updateToggleButtons
cls

rem draw our buttons, and slider
echo %esc%[11;1HValue: %slideValue%%esc%[0m%toggleDisplay%%sliderBar%%sliderPos%%button[0]%%button[1]%%button[2]%%button[3]%

rem draw a circle
set "circleColor=!color[%currentToggle%]!"
( for /l %%a in (0,10,360) do ( set /a "cx=slideValue * !cos:x=%%a! + bx", "cy=slideValue * !sin:x=%%a! + by"
	<nul set /p "=%esc%[!cy!;!cx!H%esc%[38;5;%circleColor%m#"
) ) & echo %esc%[0m

rem ask for a mouse click
%allowMouseClicks%

rem check if a button has been clicked
%ifUserClicksButton[0]% set /a "bx-=10"
%ifUserClicksButton[1]% set /a "bx+=10"
%ifUserClicksButton[2]% set /a "by-=10"
%ifUserClicksButton[3]% set /a "by+=10"

rem check/allow the slider to be moved
%sliderInput%

rem allow each toggle box to be toggled.
%allowToggle[0]%
%allowToggle[1]%
%allowToggle[2]%
%allowToggle[3]%
%allowToggle[4]%
goto :main


:createSlider
	for /l %%a in (1,1,%~3) do set "slider=!slider!-"
	set /a "spb=%~5","slider[Xmin]=%~1+1","slider[Xmax]=%~1 + %~3","sxp1=%~1+1","sym1=%~2-1","cscm=%~6","cscx=%~7"
	set "sliderBar=%esc%[%~2;%~1H%esc%[38;5;%~4m^|%slider%^|%esc%[0m"
	set "sliderPos=%esc%[%~2;%sxp1%H%esc%[38;5;%~5mÛ%esc%[0m"
	set "sliderInput=if ^!mouseY^! equ ^!sym1^! if ^!mouseX^! geq ^!slider[Xmin]^! if ^!mouseX^! leq ^!slider[Xmax]^! set /a "adaptSlide=adaptedY=mouseY + 1, slideValue=cscm+(cscx-cscm)*(mouseX-(slider[Xmin]+1))/((slider[Xmin]+slider[Xmax])-(slider[Xmin]+1))" ^& set "sliderPos=%esc%[^^!adaptedY^^!;^^!mouseX^^!H%esc%[38;5;%spb%mÛ%esc%[0m""
goto :eof

:createToggle
	if not defined toggleBoxTemplate set "toggleBoxTemplate=ÚÄÄÄ¿%esc%[B%esc%[5D³   ³%esc%[B%esc%[5DÀÄÄÄÙ%esc%[2A"
	set /a "toggleArray=%~4 - 1", "togX=%~2", "togY=%~3", "oX=togX + 1", "oY=togY + 1", "up1=togY - 1", "ov1=oX", "togCol=%~5"
	( if "%~6" neq "" ( set /a "defaultToggle=%~6" ) else ( set /a "defaultToggle=0" )) & set /a "currentToggle=defaultToggle"
	set "toggleBoxes=%esc%[%up1%;%ov1%H%~1%esc%[%togY%;%togX%H" & set "toggleOverlay=%esc%[%oY%;%oX%H"
	
	for /l %%a in (0,1,%toggleArray%) do (
		set "toggleBoxes=!toggleBoxes!%toggleBoxTemplate%"
		if %currentToggle% equ %%a ( set "toggle[%%a]=%esc%[38;5;%~5mÛÛÛ" ) else set "toggle[%%a]=%esc%[38;5;16mÛÛÛ"
		set "toggleOverlay=!toggleOverlay!!toggle[%%a]!%esc%[0m³³"
		set /a "toggleX[%%a]=(%%a + 1) * 5 + %~2 - 6"
	)
	set /a "toggleX[%~4]=(%~4 + 1) * 5 + %~2 - 6"
	
	for /l %%a in (0,1,%toggleArray%) do ( set /a "n=%%a + 1"
		for %%n in (!n!) do set "allowToggle[%%a]=if ^!mouseY^! geq ^!toggleY[min]^! if ^!mouseY^! leq ^!toggleY[max]^! if ^!mouseX^! geq ^!toggleX[%%a]^! if ^!mouseX^! lss ^!toggleX[%%n]^! set currentToggle=%%a"
	)

	set /a "toggleY[min]=%~3 - 1", "toggleY[max]=%~3 + 1"
	set "toggleOverlay=!toggleOverlay:~0,-1!"
	set "toggleDisplay=^!toggleBoxes^!%esc[0m%^!toggleOverlay^!%esc%[0m"
goto :eof


:updateToggleButtons
	set "toggleOverlay=%esc%[%oY%;%oX%H"
	for /l %%a in (0,1,%toggleArray%) do (
		if !currentToggle! equ %%a ( set "toggle[%%a]=%esc%[38;5;%togCol%mÛÛÛ" ) else set "toggle[%%a]=%esc%[38;5;16mÛÛÛ"
		set "toggleOverlay=!toggleOverlay!!toggle[%%a]!%esc%[0m³³"
	)
	set "toggleOverlay=%toggleOverlay:~0,-1%"
goto :eof

:createButton
	set /a "buttons+=1", "len=0", "buttons-=1"
	set /a "button[X][%buttons%]=%~1", "button[Y][%buttons%]=%~2"
	set "s=%~3#" & ( for %%P in (8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( if "!s:~%%P,1!" NEQ "" ( set /a "len+=%%P" & set "s=!s:~%%P!" ))) & set /a "len[%%e]=len" 2>nul
	set /a "e=len&1", "len+=(((~(0-e)>>31)&1)&((~(e-0)>>31)&1))+1", "len+=(((~(1-e)>>31)&1)&((~(e-1)>>31)&1))", "back=len + 2"
	set "buttonWidth=" & (for /l %%a in (1,1,%len%) do set "buttonWidth=!buttonWidth!Ä")
	set "button[%buttons%]=%esc%[!button[Y][%buttons%]!;!button[X][%buttons%]!HÚ%buttonWidth%¿%esc%[%back%D%esc%[B³ %~3 ³%esc%[%back%D%esc%[BÀ%buttonWidth%Ù"
	set /a "button[%buttons%][Xmin]=%~1-1","button[%buttons%][Xmax]=%~1 + len","button[%buttons%][Ymin]=%~2-1","button[%buttons%][Ymax]=%~2 + 1"
	set "ifUserClicksButton[!buttons!]=if ^!mouseY^! geq ^!button[%buttons%][Ymin]^! if ^!mouseY^! leq ^!button[%buttons%][Ymax]^! if ^!mouseX^! geq ^!button[%buttons%][Xmin]^! if ^!mouseX^! leq ^!button[%buttons%][Xmax]^!"
	set /a "buttons+=1"
goto :eof

:extras
set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
set "sin=(a=((x) * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 10000"
set "cos=(a=(15708 - (x) * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 10000"

set "color[0]=9"
set "color[1]=10"
set "color[2]=11"
set "color[3]=12"
set "color[4]=13"

set /a "by=bx=50"
goto :eof

:importantStuff
( for /f %%a in ('echo prompt $E^| cmd') do set "esc=%%a" ) & <nul set /p "=!esc![?25l"
set "allowMouseClicks=for /f "tokens=1-3" %%W in ('"bin\Mouse.exe"') do set /a "mouseC=%%W,mouseX=%%Y,mouseY=%%X""
goto :eof
documentation

Code: Select all

:important stuff

	accepts no arguments

	creates %ESC% and %allowMouseClicks%
	
	%ESC% is a necessary character in VT100, which is how the buttons are drawn and displayed
		Please GOOGLE: VT100 escape sequences
	
	%allowMouseClicks% is a argument-less macro. It is a FOR loop that accepts the input of a mouse click. Do not ECHO.
		This is captured in...
			%mouseC% - int = Left or right click
			%mouseY% - int = Y coordinate
			%mouseX% - int = X coordinate
			
			These values can be ECHO'd, but are already implemented into the functions below.
				No need to use them unless they do not involve the buttons, toggles, or slider.
			

:createSlider

	USAGE:
		call :createSlider X Y sliderLength sliderColor positionColor minRange maxRange
		
		example:
			call:createSlider 1 14 23 10 9 0 10

	creates %sliderBar%, %sliderPos%, %sliderInput%, and %slideValue%
	
	%sliderBar% and %sliderPos% are the DISPLAY of the slider bar itself, and it's current slide position
		 Simply ECHO this to display. ( echo %sliderBar%%sliderPos% )
	
	%sliderInput% collects and moves the users slider input. Do not ECHO
	
	%slideValue% is the value indictive of the current position shown on the %sliderBar%. 
		This value can be ECHO'd or used in various ways.
	

:createToggle

	USAGE:
		call :createToggle "Text above toggle bar" X Y numOfToggles color defaultToggle {defaultToggle - can be empty}
		
		example:
			call:createToggle "RED  GRE  YEL  BLU  PUR" 1 2 5 12 3

	creates %toggleDisplay%, %allowToggle[0-n]%, :updateToggleButtons
	
	%toggleDisplay% is the DISPLAY of the toggle bar. Simply ECHO this to display. ( echo %toggleDisplay% )
	
	%allowToggle[0-n]% this is the line of code you will need to allow the toggle bar to be clicked in each position.
		
		example:
			
			%allowToggle[0]%
			%allowToggle[1]%
			%allowToggle[2]%

		%allowToggle[0-n]% accepts no arguments. Do not ECHO.
	
	:updateToggleButtons 
		must be called immediately at the beginning of the loop to "update" the display of the toggle bar.
		
		example:
			
			:main
				call:updateToggleButtons
			
				Do more things, but noticed we called :updateToggleButtons immediately
			goto :main
	
	This function accepts no arguments.
	

:createButton

	USAGE:
		call :createButton X Y "Button Text"
		
		example:
			call :createButton 10 25 "Say Hello"
			
	creates %button[0-n]%, and %ifUserClicksButton[0-n]%
	
	%button[0-n]% is the DISPLAY of the button. Simply ECHO this to display. ( echo %button[0-n]% )
	
	%ifUserClicksButton[0-n]% treat this exactly like an IF statement, only it already knows the comparison. Do not ECHO.
	
		example:
			%ifUserClicksButton[0]% (
				ECHO Hello World
			)

T3RRY
Posts: 156
Joined: 06 May 2020 10:14

Re: Button functions via VT100, and Mouse.exe

#2 Post by T3RRY » 13 Jun 2021 07:55

A very nice tool you've made there Icarus. I can see it being easy enough to create a callable function for output of and selection from a dynamic menu. I've played around a bit with the functions currently scripted and added parameters for button color and button text color.

Edit: As expected, its a fairly simple thing to script a function to call createbutton to output a menu
I've reworked the function to suit my tastes and built a switch into it to flag a button as being toggleable.
Display of toggled buttons is automated using a function calle by a reworked version of the ifuserclicksbutton[#] macro.
Toggle buttons now track their state.
A single macro can be expanded to id which button was pressed, returning the index of the button and the selected text string.
By switching to BG.exe instead of mouse.exe I was also able to add in a sound effect when valid buttons are clicked.
I also added handling of the reg value for QuickEdit mode to disable it during script execution and enable it at script completion.

View demo: https://youtu.be/PF48p5bpDgw

Code: Select all

@Echo off & CD /d "%~dp0"

:# Based on: https://www.dostips.com/forum/viewtopic.php?f=3&t=9222
:# example begins at 'main' label at end of file

 If not exist "%~dp0Components\" MD "%~dp0Components\"
 If not exist "%~dp0Components\BG.exe" Certutil -decode "%~f0" "%~dp0Components\BG.exe"
cls
 Set "reg.restore=(Call )"

rem disable QuickEdit if enabled. Restored at :end label if disabled by script
  reg query HKEY_CURRENT_USER\console\ /v Quickedit | findstr.exe /l "0x1" > nul && (
   (Reg add HKEY_CURRENT_USER\console\ /v QuickEdit /t REG_DWORD /d 0x0 /f) > nul
   Set "reg.restore=Reg add HKEY_CURRENT_USER\console\ /v QuickEdit /t REG_DWORD /d 0x1 /f"
  )

 For /f "tokens=4 Delims=: " %%C in ('CHCP')Do Set "active.cp=%%C"
 chcp 65001 > nul
 For /f %%e in ('echo prompt $E^|cmd')Do Set \E=%%e
 If "!!" == "" (Echo DelayedExpansion must not be enabled before macro definitions&Pause & Exit /B 1)

Rem button sound disable by undefining buttonsfx below ; prior to definition of OnCLick macro
 Set "buttonsfx=On"
 Components\BG.exe Play "%HOMEDRIVE%\Windows\Media\Windows Feed Discovered.wav"
 Set "OnClick=(Call )"
 Set "OnType=(Call )"
 If defined buttonsfx (
  Set "OnClick=(Components\BG.exe Play "%HOMEDRIVE%\Windows\Media\Windows Feed Discovered.wav")"
  For /f "Delims=" %%G in ('Dir /b /s "%HOMEDRIVE%\Windows\SystemApps\*KbdKeyTap.wav"')Do If exist "%%~G" Set "OnType=(Components\BG.exe Play "%%~G")"
 )

rem return button click coords in c{pos} variable n Y;X format
 Set "GetClick=Set "Clicked="& Set "ValidClick="& for /f "tokens=1,2" %%X in ('Components\BG.exe mouse')Do (Set /A "c{pos}=%%X+1"&Set "c{pos}=%%Y;!c{Pos}!")"

Rem test substituted button # if click is within btn[#][coords] defines variables: Clicked [value eq string] ; ValidClick [value eq button number / undefined]; State{btn[#]} [value eq true/false]
 Set "If.Button=For /f "Tokens=1,2 Delims=;" %%X in ("!c{pos}!")Do If not "!btn[#][Coords]:[%%Y;%%X]=!" == "!btn[#][Coords]!" Set "Clicked=!btn[#][string]!"& Set "ValidClick=#"& (If defined btn[#]{t} Call :Toggle #)& "

Rem tests all buttons in same way as if.clicked ; exclude a button via substring modification substituting 'exc' for 'button#'
 Set "qClicked=(For /l %%i in (1 1 !buttons!)Do If not "%%i"=="Exc" For /f "Tokens=1,2 Delims=;" %%X in ("!c{pos}!")Do If not "!btn[%%i][Coords]:[%%Y;%%X]=!" == "!btn[%%i][Coords]!" Set "Clicked=!btn[%%i][string]!"& Set "ValidClick=%%i"& %OnClick% & (If defined btn[%%i]{t} Call :Toggle %%i))& "

Rem display all buttons
 Set "dButtons=For /l %%i In (1 1 !buttons!)Do <nul Set /P "=!btn[%%i]!""

rem displays all selected button or input values
 Set "dValues=For /l %%i in (1 1 !buttons!)Do if defined State{btn[%%i]} (set "value=%\E%[0;7m!State{btn[%%i]}:true=%\E%[0;32mtrue!"& Echo(%\E%[33mButton[%%i]%\E%[36m=!value:false=%\E%[0;90mfalse!%\E%[0m)"

 Setlocal EnableDelayedExpansion
 <nul set /p "=%\E%[?25l"

rem menu macro for easily creating multiple buttons simultaneously
 Set "CHash=Col"
 set "menu=Set "m{\c}="& For %%n in (1 2)Do if %%n==2 ((If "^^!CHash^^!"=="Col" (Set "m{\c}="&Call:createmenu ^!Params^! 2> nul )Else (Set /A "m{\c}=Col"&Call :Createmenu ^!Params^! 2> nul ))& Set "m{\c}="&Set "m{x}=2")Else Set Params="
 Call :DefKeys

==========
Goto :Main
==========

rem FUNCTIONS

====
:end
 (%Reg.Restore%) > nul
 (Title )
 <nul set /p "=%\E%[?25h"
 CHCP %active.cp% > nul
 Endlocal
Goto :Eof

=================
:Toggle <button#>
 If "!State{btn[%~1]}!"=="true" (
  <nul set /P "=!btn[%~1]!"
  Set "State{btn[%~1]}=false"
 )Else (
  <nul set /P "=!btn[%~1]:48=7;48!"
  Set "State{btn[%~1]}=true"
 )
Exit /b 0

==========================================================
:createbutton <string> <y> <x> <FGcol> <BGcol> <BTNcol> -t
:# Arg Structure: 1,2,3 =  Mandatory ; 4,5,6 = Optional ; -t = Optional switch. Must be Last arg if present.

:# Button Border ; Recommended font: Lucida Console
:# Codepage:         65001
:# alt 201 alt 205 alt 187 ╔═╗
:# alt 186  space  alt 186 ║ ║
:# alt 200 alt 205 alt 188 ╚═╝

 set "l[Y]=!btn[Y]!"
 Set /A "btn[Y]=%~2+3"
 If "%~3" == "" Exit /b 1
 Set /a "buttons+=1+0"
 Set "btn[%buttons%][p]=%~2;%~3"
 Set "btn[%Buttons%][string]=%~1"

 If "%~4" == "-t" (set "btn[BG]=%\E%[48;2;230;230;200m")Else If "%~4" == "" (set "btn[BG]=%\E%[48;2;230;230;200m")Else set "btn[BG]=%\E%[38;2;%~4m"
 If "%~5" == "-t" (set "btn[FG]=%\E%[38;2;;;m")Else If "%~5" == "" (set "btn[FG]=%\E%[38;2;;;m")Else set "btn[FG]=%\E%[48;2;%~5m"
 If "%~6" == "-t" (set "btn[Col]=%\E%[90m")Else If "%~6" == "" (set "btn[Col]=%\E%[90m")Else set "btn[Col]=%\E%[%~6m"

:# Rem defines variable identifying button as toggle button; used by %If.Button% and %qClicked% macros
 Echo("%*"|findstr /lic:"-t" > nul && Set "btn[%buttons%]{t}=true" || Set "btn[%buttons%]{t}="

 Set "len="& For /l %%i in (0,1,120)Do if "!len!"=="" If "!btn[%Buttons%][string]:~%%i,1!"=="" Set "len=%%i"
 Set /A "btn{Xmin}=%3+1", "btn{Xmax}=%3+len", "l[X]=btn{Xmax}+2"
 Set "btn[%buttons%][Len]=" & Set "btn[%buttons%][S]=" & Set "btn[%Buttons%][coords]="

rem define button click coords and button Upper / lower border
 For /l %%i in (!btn{Xmin}! 1 !btn{Xmax}!)Do (
  Set /a "Xoffset=%%i-1"
  Set "btn[%Buttons%][coords]=!btn[%Buttons%][coords]![%2;!Xoffset!]"
  Set "btn[%buttons%][Bar]=!btn[%buttons%][Bar]!═"
  Set "btn[%buttons%][S]=!btn[%buttons%][S]! "
 )
 Set /A "btn[%buttons%][Len]=btn{Xmax}-btn{Xmin}"

Rem toggle state varaiable
 If defined btn[%buttons%]{t} Set "State{btn[%buttons%]}=false"

Rem Button Graphic. Toggle is effected by substituting Background color VT code 48 with 7;48 to invert button text color.
 Set "btn[%buttons%]=%\E%[%2;%3H%Btn[col]%%\E%7║%\E%8%\E%A╔!btn[%buttons%][Bar]!╗%\E%8%\E%B╚!btn[%buttons%][Bar]!╝%\E%8%\E%C%\E%[0m!btn[FG]!!btn[BG]!!btn[%buttons%][String]!%\E%[0m%btn[col]%║%\E%[0m%\E%[2E%\E%7"
 Set "btn[%buttons%][t]=%\E%[0m!btn[FG]!!btn[BG]!!btn[%buttons%][String]!%\E%[0m%btn[col]%║%\E%[0m%\E%[K"
Exit /b 0

==========================================
:createMenu <"list" "of" "button strings">
:# Associated Macro: %Menu%
:#  - Uses default values for button color schemes m{fg} m{bg} and m{olc}
:#    - Define the value of those variables prior to calling :createMenu
:#      to the desired color scheme if you wish to override default values.
:#  - Defaults to column 1 if m{x} is not defined with a column value
:#    - m{\c} overides m{x} to value of the new column. %Menu% macro resets m{x} to 2 as default x pos after use.
:#  - Button count is reset unless m{\c} is defined using substring modification of
:#    - %menu% macro: Ie: %Menu:Col=15% list of options
:#      - Int X pos value for new column
:# ! Note: Columns are not automatically padded for options of different lengths.
:#  - Use white space in options list to pad options for buttons of equal size.
:#    IE: %Menu% "      short button       " "A Very Much Longer Button"

 If not defined m{\c} (
  cls
  Set "buttons="
  Set "display.menu=Call Echo("
  Set "b{i}=0"
 )
 Set "b{y}=3"
 If not defined m{fg} (Set "m{fg}=;160;200")
 If not defined m{bg} (Set "m{bg}=150;;150")
 If not defined m{olc} (Set "m{olc}=33")
 If defined m{\c} (Set "m{x}=!m{\c}!")
 If not defined m{x} (Set "m{x}=2")
 For %%v in (%*)Do (
  Call :CreateButton "%%~v" !b{y}! !m{x}! "!m{fg}!" "!m{bg}!" !m{olc}! -t 2> nul
  Set "display.menu=!display.menu!%%button[!b{i}!]%%"
  Set /a "b{y}+=3", "b{i}+=1"
 )
 %display.menu%
Exit /b 0

============================
:InputBar <button#> <Prompt>
 Title %~2
 set "input="
 Set /A "Currin=0","MaxIn=!btn[%1][Len]!"
 <nul Set /P "=%\E%[!btn[%1][p]!H%\E%C%\E%7%\E%[0;7m%\E%[?25h%\E%[?12h"
:entryloop
 Components\BG.exe kbd
 Set "key=!k[%Errorlevel%]!"
 If not "!Key!" == "" (
  If not "!Key!"=="Enter" (
   If "!Key!"=="Backspace" If not !CurrIn!==0 (
    Set "Input=!Input:~0,-1!"
    Set /A CurrIn-=1
    <nul set /p "=%\E%[48;2;;;m%\E%D %\E%D"
   )
   If !MaxIn! GTR !CurrIn! If not "!Key!"=="Backspace" (
    Echo("!Key!"|findstr.exe /lic:"space" /lic:"tab" /lic:"left" /lic:"right" /lic:"up" /lic:"down" /lic:"delete" /lic:"escape" > nul && (For /f "delims=" %%v in ("!Key!")Do Set "Input=!Input!!%%v!") || Set "Input=!Input!!Key!"
    Echo("!Key!"|findstr.exe /lic:"left" /lic:"tab" /lic:"right" /lic:"up" /lic:"down" /lic:"delete" /lic:"escape" > nul || Set /A CurrIn+=1
   )
   %OnType%
   <nul set /p "=%\E%8%\E%[0m!Input!"
   Goto:entryloop
  )
 )
 <nul Set /P "=%\E%[?25l%\E%8%\E%[K!btn[%1][t]:255=0!"
 If "!input!" == "" (
  Components\BG.exe play "%HOMEDRIVE%\Windows\Media\Windows Error.wav"
  Goto :InputBar
 )
 Components\BG.exe play "%HOMEDRIVE%\Windows\Media\Windows Navigation Start.wav"
 <nul Set /P "=%\E%8!btn[%1][t]!"
 If "!input!" == "" Goto :InputBar
 Set "State{btn[%1]}=!Input!"
 Title You Entered: !Input!
Exit /B

:DefKeys
(Set LF=^


%= empty lines above are required. =%)

Set "k[8]=Backspace"

rem For /l %%i in (9)Do For /F eol^=^%LF%%LF%^ delims^= %%A in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x09"') do Set "k[9]=%%A"

Set "k[13]=Enter"
Set "k[27]=Escape"
Set "k[32]=Space"
Set "Space= "
Set "k[33]=^!"
Set ^"k[34]=""

set "i=35"

 For %%k in (
 "#" "$" "%%" "&" "'" "(" ")" "AS" "+" "," "-" "." "/"^
 "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"^
 ":" ";" "<" "=" ">" "qm" "@"^
 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z^
 "[" "\" "]" "^^" "_" "`"^
 a b c d e f g h i j k l m n o p q r s t u v w x y z^
 )Do (
  Set "k[!i!]=%%~k"
  Set /A "i+=1"
 )
 Set "k[42]=*"
 Set "k[63]=?"
 Set "k[123]={"
 Set "k[124]=|"
 Set "k[125]=}"
 Set "k[126]=~" 
 Set "k[339]=Delete"
 Set "k[328]=Up"
 Set "k[331]=Left"
 Set "k[333]=Right"
 Set "k[336]=Down"
Exit /b 0

rem UTILITY

===============
/* BG.exe V 3.9
  https://github.com/carlos-montiers/consolesoft-mirror/blob/master/bg/README.md
  Copyright (C) 2010-2018 Carlos Montiers Aguilera

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

  Carlos Montiers Aguilera
  cmontiers@gmail.com
 */

-----BEGIN CERTIFICATE-----
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v
dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAATAEEAG3tp1sAAAAA
AAAAAOAADwMLAQIZABoAAAAIAAAAAgAAcCcAAAAQAAAAAMD/AABAAAAQAAAAAgAA
BAAAAAEAAAAEAAAAAAAAAABgAAAABAAAu00AAAMAAAAAACAAABAAAAAAEAAAEAAA
AAAAABAAAAAAAAAAAAAAAABQAABMBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAD4UAAAlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC50ZXh0AAAA
IBkAAAAQAAAAGgAAAAQAAAAAAAAAAAAAAAAAACAAUGAucmRhdGEAALgBAAAAMAAA
AAIAAAAeAAAAAAAAAAAAAAAAAABAAGBALmJzcwAAAACMAAAAAEAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAgABgwC5pZGF0YQAATAQAAABQAAAABgAAACAAAAAAAAAAAAAA
AAAAAEAAMMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
-----END CERTIFICATE-----
	
:Main script body
Rem USAGE EXAMPLES

 %Menu% "Option 1" "Option 2" "Option 3"
 %Menu:Col=l[X]% "Option 4" "Option 5" "Option 6"
 %Menu:Col=l[X]% "Option 7" "Option 8" "Option 9"

 Call :createButton "Click Me" !btn[Y]! 2 -t
 Call :createButton "Or Me" !l[Y]! !l[X]! -t
 Call :createButton "                                                   " !l[Y]! 2 "0;0;0" "255;255;255" "36" -t
 Call :createButton "Exit" !btn[Y]! 2 "200;;" "155;155;255" "48;2;60;;"

%dButtons%

:loop
 %GetClick%
 %qClicked% If defined ValidClick (
  Title Clicked Button !ValidClick! : "!Clicked:  =!"
  If "!Clicked:~-5!"=="     " Call :InputBar !ValidClick! "Enter something:" > Con
  If "!Clicked!"=="Exit" (
   <nul Set /P "=%\E%[!btn[Y]!d%\E%[G"
rem iterate over botton array and display values in index order
   %dValues%
   Goto :End
   )
  )Else (
   Title Clicked: !C{Pos}!
  )
 )
Goto :loop


Took a crack at trying to run mouse.exe from a second thread in order to be able to use the input in a non blocking way, unfortunately no luck. The thread hung while the primary looped - I expect mouse.exe recieved no input from the second thread due to the firsts ongoing execution.
Last edited by T3RRY on 18 Jun 2021 04:41, edited 10 times in total.

Lowsun
Posts: 18
Joined: 14 Apr 2019 17:22

Re: Button functions via VT100, and Mouse.exe

#3 Post by Lowsun » 13 Jun 2021 17:01

Interesting. I've made something similar using Powershell instead of mouse.exe, though the method I use means it only works in full screen. I remember seeing a post by Aacini to multithread Powershell, so I used this snippet

Code: Select all

POWERSHELL  ^
Add-Type -AssemblyName System.Windows.Forms;  ^
$A = [math]::round([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width / $Host.UI.RawUI.WindowSize.Width);  ^
$B = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height / $Host.UI.RawUI.WindowSize.Height;  ^
while($true) {  ^
  $X = [math]::round([System.Windows.Forms.Cursor]::Position.X / $A);  ^
  $Y = [math]::round([System.Windows.Forms.Cursor]::Position.Y / $B);  ^
  $M = [System.Windows.Forms.UserControl]::MouseButtons;  ^
  Write-Output "$X-$Y-$M"  ^
} | "%~F0" GAME
to have Powershell put the coordinates/mouse to Batch, and a simple Button function. This script creates three buttons which you can press using mouse.

Code: Select all

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
IF not "%~1" == "" (
    GOTO :%~1
)
START /MAX "" "%~F0" START
EXIT

:START
FOR /F "tokens=3" %%A in ('REG QUERY "HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics" /v CaptionHeight') DO (
    SET /A "title=%%A / -15"
)
FOR /F %%A in ('ECHO prompt $E^| cmd') DO SET "ESC=%%A"
CALL :MAKEBUTTON 5 5 10 5 "Button 1" "20;120;20" "200;100;100"
SET "bu[1]=%bu[button]%"&SET "bu[1coord]=%bu[coord]%"
CALL :MAKEBUTTON 30 5 12 9 "Hey there" "2550;100;30" "25;25;45"
SET "bu[2]=%bu[button]%"&SET "bu[2coord]=%bu[coord]%"
CALL :MAKEBUTTON 50 5 8 7 "Cool" "50;168;160" "32;18;69"
SET "bu[3]=%bu[button]%"&SET "bu[3coord]=%bu[coord]%"

:CONTROL
ECHO Loading...
POWERSHELL  ^
Add-Type -AssemblyName System.Windows.Forms;  ^
$A = [math]::round([System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Width / $Host.UI.RawUI.WindowSize.Width);  ^
$B = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Height / $Host.UI.RawUI.WindowSize.Height;  ^
Write-Output "Okay";  ^
while($true) {  ^
  $X = [math]::round([System.Windows.Forms.Cursor]::Position.X / $A);  ^
  $Y = [math]::round([System.Windows.Forms.Cursor]::Position.Y / $B);  ^
  $M = [System.Windows.Forms.UserControl]::MouseButtons;  ^
  Write-Output "$X-$Y-$M"  ^
} | "%~F0" GAME
EXIT

:GAME
FOR /L %%# in () DO (
    SET /P "com="
    IF defined com (
        IF "!com:-=!" == "!com!" (
            TITLE Click on the Button^^!
            ECHO %ESC%[?25l%ESC%[2J%bu[1]%%bu[2]%%bu[3]%
        ) else (
            FOR /F "tokens=1-3 delims=-" %%A in ("!com!") DO (
                IF not "%%C" == "None" (
                    FOR /L %%Q in (1, 1, 3) DO (
                        IF not "!bu[%%Qcoord]:%%B;%%A=!" == "!bu[%%Qcoord]!" (
                            ECHO %ESC%[20;20H You pressed the Button %%Q^^!
                        )
                    )
                )
            )
        )
        SET "com="
    )
)

:MAKEBUTTON <x> <y> <w> <h> <text> <coltext> <colbg>
SETLOCAL
SET "bu[coord]="&SET "bu[border]="&SET "bu[button]=%ESC%[%2;%1H"&SET "bu[text]=%~5"
CALL :STRLEN bu[text] bu[text]
SET /A "bu[space]=(%3 - bu[text]) / 2", "bu[center]=((%4 - 1) / 2) + %2"
FOR /L %%X in (1, 1, %3) DO (
    SET "bu[border]=!bu[border]!Û"
)
FOR /L %%Y in (0, 1, %4) DO (
    SET /A "d[y]=%2 + %%Y"
    FOR /L %%X in (0, 1, %3) DO (
        SET /A "d[x]=%1 + %%X"
        SET "bu[coord]=!bu[coord]!$!d[y]!;!d[x]!"
    )
    SET "bu[button]=!bu[button]!%bu[border]%%ESC%[B%ESC%[%1G"
)
ENDLOCAL&SET "bu[coord]=%bu[coord]%$"&SET "bu[button]=%ESC%[38;2;%~7m%bu[button]%%ESC%[%bu[center]%;%1H%ESC%[%bu[space]%C%ESC%[48;2;%~7m%ESC%[38;2;%~6m%~5%ESC%[0m"
GOTO :EOF

::from user jeb from stackoverflow
:strlen <resultVar> <stringVar>
(   
    setlocal EnableDelayedExpansion
    (set^ tmp=!%~2!)
    if defined tmp (
        set "len=1"
        for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
            if "!tmp:~%%P,1!" NEQ "" ( 
                set /a "len+=%%P"
                set "tmp=!tmp:~%%P!"
            )
        )
    ) ELSE (
        set len=0
    )
)
( 
    endlocal
    set "%~1=%len%"
    exit /b
)

T3RRY
Posts: 156
Joined: 06 May 2020 10:14

Re: Button functions via VT100, and Mouse.exe

#4 Post by T3RRY » 14 Jun 2021 05:18

Again, very nice lowsum. the multithreading gives it alot of potential for use as a means of input during gameplay. I'll have to find time to play around with it to see how accurate the coordinate reads are.

Post Reply