Jump to content











Photo
- - - - -

Basic batch Menu using arrows keys?


Best Answer grrrd , 08 February 2016 - 02:32 PM

You can see if Nircmd will work, i use that on full Windows, never tried on PE.

 

http://www.nirsoft.n...ils/nircmd.html

Go to the full post


  • Please log in to reply
20 replies to this topic

#1 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 04 February 2016 - 11:02 AM

Hi,

i'm using WinPE and i'm creating menus with choice command.

But i want to use arrow keys to navigate my menus. is it possible?

Thanks



#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 05 February 2016 - 08:06 AM

You need a program, *like* (examples):

http://www.dostips.c....php?f=3&t=3428

http://binnyva.com/pro/dos/batch_tk/

 

:duff:

Wonko


  • guimenez likes this

#3 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 05 February 2016 - 08:26 AM

You need a program, *like* (examples):

http://www.dostips.c....php?f=3&t=3428

http://binnyva.com/pro/dos/batch_tk/

 

:duff:

Wonko

Thank you,

the main problem it's that i'm using a basic WinPE x86 and another one x64, and does program doesn't work in x64 :(

But i found a perfect solution and it's amazing how it works :D

Now i'm only trying to put a menu title in there, that's another history.

Thanks once again

 

This is the nice batch: http://www.dostips.c....php?f=3&t=5661



#4 Guest_AnonVendetta_*

Guest_AnonVendetta_*
  • Guests

Posted 05 February 2016 - 05:01 PM

AutoIt or AutoHotkey might be able to do the trick too. Just convert your script into a standalone *.exe so it can run without needing either program to be installed.


  • guimenez likes this

#5 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 07 February 2016 - 11:02 PM

Now that i've a great menu using arrow keys, i need to center the window on the screen, is it possible?

my startnet.cmd opens my menu.cmd and i want that menu opened in center of the screen.

If a adjust the window properties it works well, but after restart it's not centered :(

thanks



#6 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 135 posts
  •  
    United Kingdom

Posted 08 February 2016 - 02:32 PM   Best Answer

You can see if Nircmd will work, i use that on full Windows, never tried on PE.

 

http://www.nirsoft.n...ils/nircmd.html


  • guimenez likes this

#7 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 08 February 2016 - 07:25 PM

Just perfect that tool.
Thank you :)

#8 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 13 February 2016 - 11:07 PM

I adapted the batch file in the dostips link. Copy it into a separate .cmd file.

This version allows the caller to specify a list of phrases and returns the selection in the var variable

If you don't specify any argument then a test list will be used.

 

Note: better version a few posts down!

@if (@CodeSection == @Batch) @then
rem Usage: xxx.cmd "first choice" "second choice" third fourth
rem Returns user choice as var variable - e.g. var=first choice
rem Screen is cleared on exit
@echo off
setlocal EnableDelayedExpansion
rem Multi-line menu with options selection via DOSKEY
rem Antonio Perez Ayala
rem Define the options
set numOpts=0
if "%1" equ "" set OPT="This is the First" Second Third Fourth Fifth "666 66" "777 777" 888 999 10101 111 1212
if not "%1" equ "" set OPT=%*
for %%a in (%OPT%) do (
   set /A numOpts+=1
   set aa=%%a
   set option[!numOpts!]=!aa:"=!
)
set /A numOpts+=1
set "option[!numOpts!]=exit"
rem Clear previous doskey history
doskey /LISTSIZE=!numOpts!
rem Fill doskey history with menu options
cscript //nologo /E:JScript "%~f0" EnterOpts
for /L %%i in (1,1,%numOpts%) do set /P "var="
:nextOpt
cls
rem echo MULTI-LINE MENU WITH OPTIONS SELECTION
rem echo/
rem Send a F7 key to open the selection menu
cscript //nologo /E:JScript "%~f0" > nul
set var=
set /P "var=Select the desired option: " > nul
endlocal & set var=%var%
doskey /LISTSIZE=0
cls
goto :eof
@end
var wshShell = WScript.CreateObject("WScript.Shell"),
    envVar = wshShell.Environment("Process"),
    numOpts = parseInt(envVar("numOpts"));
if ( WScript.Arguments.Length ) {
   // Enter menu options
   for ( var i=1; i <= numOpts; i++ ) {
      wshShell.SendKeys(envVar("option["+i+"]")+"{ENTER}");
   }
} else {
   // Enter a F7 to open the menu
   wshShell.SendKeys("{F7}");
   wshShell.SendKeys("{HOME}");
}

  • guimenez likes this

#9 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 14 February 2016 - 10:27 AM

Amazing like always Steve :)
I will try it out.
Thanks

#10 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 14 February 2016 - 11:02 AM

Good. :)

Just for the record (and in case of similar use) this:

for %%a in (%OPT%) do (
set /A numOpts+=1
set aa=%%a
set option[!numOpts!]=!aa:"=!
)

can be simplified into a  one-liner:

for %%a in (%OPT%) do set /A numOpts+=1&&set option[!numOpts!]=%%~a

:duff:

Wonko


  • guimenez likes this

#11 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 14 February 2016 - 11:13 AM

I'm getting now a perfect menu choice in Winpe.
Thank you all

#12 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 14 February 2016 - 11:30 AM

If you don't want an exit entry then delete the two lines:

set /A numOpts+=1
set "option[!numOpts!]=exit"

Not sure if it works in your WinPE, but you can also try these commands to change the console window

TITLE Mytitle
mode con: cols=90 lines=30
color 1f

  • guimenez likes this

#13 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 14 February 2016 - 11:54 AM

I've removed the exit and i'm using the mode to reduce command prompt window and nircmd to center it :)
Is it possible to increase the white menu window?
I can only have 10 entries the rest just showing when moving cursor down.
Thanks

#14 steve6375

steve6375

    Platinum Member

  • Developer
  • 7566 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films
  •  
    United Kingdom

Posted 14 February 2016 - 12:14 PM

@if (@CodeSection == @Batch) @then
@echo off
rem Usage: xxx.cmd "first choice" "second choice" third fourth
rem Returns user choice as var variable - e.g. var=first choice
rem Screen is cleared on exit
setlocal EnableDelayedExpansion
rem Multi-line menu with options selection via DOSKEY
rem Antonio Perez Ayala
rem Define the options
set numOpts=0
set OPT=%*
if not DEFINED OPT set OPT="This is the First" Second Third Fourth Fifth "666 66" "777 777" 888 999 10101 111 1212
for %%a in (%OPT%) do set /A numOpts+=1&&set option[!numOpts!]=%%~a
rem Clear previous doskey history
doskey /LISTSIZE=!numOpts!
rem Fill doskey history with menu options
cscript //nologo /E:JScript "%~f0" EnterOpts
for /L %%i in (1,1,%numOpts%) do set /P "var="
cls
rem Send a F7 key to open the selection menu
cscript //nologo /E:JScript "%~f0" > nul
set var=
set /P "var=Select the desired option: " > nul
endlocal & set var=%var%
doskey /LISTSIZE=0
cls
goto :eof
@end
var wshShell = WScript.CreateObject("WScript.Shell"),
    envVar = wshShell.Environment("Process"),
    numOpts = parseInt(envVar("numOpts"));
if ( WScript.Arguments.Length ) {
   // Enter menu options
   for ( var i=1; i <= numOpts; i++ ) {
      wshShell.SendKeys(envVar("option["+i+"]")+"{ENTER}");
   }
} else {
   // Enter a F7 to open the menu
   wshShell.SendKeys("{F7}");
   wshShell.SendKeys("{HOME}");
}

Here is improved version with Wonko's suggestion + some bugs fixed when using command parameters with double-quotes and it now does not echo rem lines.

 

I think the size of the DOSKEY window is fixed? :dubbio:


Edited by steve6375, 14 February 2016 - 12:17 PM.

  • guimenez likes this

#15 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 14 February 2016 - 12:16 PM

Maybe.
I can live with that but it will be better if I increase the window :)

#16 Zharif

Zharif

    Frequent Member

  • .script developer
  • 172 posts
  • Location:Germany
  •  
    Germany

Posted 14 February 2016 - 12:47 PM

I didn't try these tools.

But there's a powershell solution to increase/decrease winWidth/Height as well as bufWidth/Height.

Tested on WinXP with SP3 and Win10.

 

Here's an example. Adapt it to your needs:

:: Console Resize values via PowerShell (changeable)
SET "_PSResize=100 54 100 9997"

:: Check for powershell via PATH variable
POWERSHELL "Exit" >NUL 2>&1 && SET "_PS=1"
IF NOT DEFINED _PS (ECHO No&do something) ELSE (ECHO Yes&do something)
 
:: PS-Console Resizing
IF DEFINED _PS CALL:_PS_ReSize %_PSRESIZE%
 
:_PS_Resize  bufWidth  bufHeight  winWidth  winHeight
:: Mode sets buffer size-not window size
MODE %1,%2

:: resize
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%3;$B.height=%4;$W.buffersize=$B;}"
GOTO:EOF

  • guimenez likes this

#17 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 14 February 2016 - 12:59 PM

I didn't try these tools.
But there's a powershell solution to increase/decrease winWidth/Height as well as bufWidth/Height.
Tested on WinXP with SP3 and Win10.
 
Here's an example. Adapt it to your needs:

:: Console Resize values via PowerShell (changeable)
SET "_PSResize=100 54 100 9997"

:: Check for powershell via PATH variable
POWERSHELL "Exit" >NUL 2>&1 && SET "_PS=1"
IF NOT DEFINED _PS (ECHO No&do something) ELSE (ECHO Yes&do something)
 
:: PS-Console Resizing
IF DEFINED _PS CALL:_PS_ReSize %_PSRESIZE%
 
:_PS_Resize  bufWidth  bufHeight  winWidth  winHeight
:: Mode sets buffer size-not window size
MODE %1,%2

:: resize
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%3;$B.height=%4;$W.buffersize=$B;}"
GOTO:EOF

I think that will resize command Window and not Disney window :(

#18 Zharif

Zharif

    Frequent Member

  • .script developer
  • 172 posts
  • Location:Germany
  •  
    Germany

Posted 14 February 2016 - 01:12 PM

This was nothing than an idea in hope it could be somehow implemented.

Again, I never worked with this kind of menu. Therefore I'm not able to assist.

 

Sorry for intruding your thread.


  • guimenez likes this

#19 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 14 February 2016 - 01:22 PM

... if an exit is actually wanted we can even remove the IF condition:
set OPT="This is the First" Second Third Fourth Fifth "666 66" "777 777" 888 999 10101 111 1212 %*
set OPT=!OPT:%OPT%=%* exit!
(not that it would make any noticeable difference)

:duff:
Wonko
  • guimenez likes this

#20 guimenez

guimenez

    Frequent Member

  • Advanced user
  • 172 posts
  •  
    Portugal

Posted 14 February 2016 - 01:59 PM

This was nothing than an idea in hope it could be somehow implemented.
Again, I never worked with this kind of menu. Therefore I'm not able to assist.
 
Sorry for intruding your thread.


It's ok, any help is appreciated :)

#21 AceInfinity

AceInfinity

    Frequent Member

  • Team Reboot
  • 228 posts
  • Location:Canada
  • Interests:Windows Security, Programming, Customizing & Crash Dump Analysis.
  •  
    Canada

Posted 15 February 2016 - 08:32 AM

I wrote quite a few of my own helper functions. They provide you a StrLen.exe which you don't really need. You can still determine the length of a string in batch alone, I've done it before with my own callable section of a batch script using batch substrings.

 

Looks like a nice solution was created throughout this thread though :)


  • guimenez likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users