Mouse-Selectable Menu from a data file - a/la CHOICE

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Mouse-Selectable Menu from a data file - a/la CHOICE

#1 Post by thefeduke » 17 Nov 2016 00:58

Torn between having already overworked this script to make it better and reaping the potential benefits of the critique of the DOStips community, I am releasing the code in its current state:
MChoice.bat wrote::::
::: Usage Notes:
:::
:::
::: Usage Considerations
:::
::: This script is primarily designed to provide a MENU application
::: where the choice is selected by using the mouse rather then the
::: keyboard. Although vaguely modeled on the CHOICE command, the
::: design removes restrictions on the number of choices available and
::: does not require the interpretation of return codes and the
::: associated hard-coded decisions. The input file defines the MENU
::: and the returned string is as it appears on the display. These
::: data are easily changed and can be made to require as much parsing
::: as desired or to be self-defining, even to the point of being
::: directly executable. The basics do appear to work on Windows XP.
:::
This first post will remain the focus for all changes.

Here is output from supplied test data. Edit: Original text output is replaced by a similar screen image for dramatic effect. ImageAttachment, version 0.0, revised:
Mouser.zip
MChoice.bat, prerequisites and test data.
Added ReadME and refined testdata
(45.36 KiB) Downloaded 1479 times

John A.
Last edited by thefeduke on 21 Nov 2016 00:22, edited 2 times in total.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#2 Post by thefeduke » 17 Nov 2016 02:12

Starting right in with my own improvement suggestion, CHOICE has options for a timeout and a default selection. I thought that it should be possible to do that, but I have not been able to make it work.

I have a test script, taken out of context, below. It attempts to use the /T flag of the GetInput.exe from "topic:: "Advanced Batch features via auxiliary .exe programs" by Aacini at http://www.dostips.com/forum/viewtopic.php?p=17101#p17101. Can someone see an obvious logic error or how I may have misinterpreted the instructions for using this option?

Here is my test script:

Code: Select all

@Echo Off&SetLocal EnableDelayedExpansion
    Set "windowCols=80"
    CLS
    Echo(A few Fields in row 00
    Echo(Row 1
    Echo('Esc' to terminate.
    Echo(
    Echo(Row # 4
    Echo(
    Echo(Use the keyboard or mouse now.
     
:Basic     
    GetInput /T 0
    Set /A "input=%errorlevel%"
    If %input% EQU 0 Show "timed out at %time%" 13 10
    If "%input%" EQU "27" GoTo :Nextloop
    If %input% GTR 0 Show "Keyboard activity detected." 13 10
    If %input% LSS 0 Show "Mouse activity detected." 13 10
    Goto :Basic
     
:NextLoop     
    Echo(Starting another input loop
    CursorPos&Set /A "BotRow=((!errorlevel!>>16)&0xFFFF)-2, MsgRow=BotRow+3"
::  Interpret moused location using AuxProgram: GetInput
:InLoop
    CursorPos 0 %MsgRow%
    GetInput /T 9000
    Set /A "input=%errorlevel%"
    If %input% GTR 0 (
        CursorPos 0 -1
        If "%input%" EQU "27" (
            Set /A "CSlen=WindowCols-73"
            ColorShow / "Simulating a termination click because the '" "Esc"  "' key was pressed. " 32x!CSlen! 13 10 /07
            ColorShow / 32x%WindowCols% /
            Set "MRow=%BotRow%"
            Set "MClick=Left"
            CursorPos 0 %MsgRow%
            Goto :Escape
Rem.        Possible future use - filter numerals for multiple word selection
        ) Else (
            Set /A "CSlen=WindowCols-18"
            ColorShow / "A key, loosely interpreted as the '" %input%  "' key was pressed. " 32x!CSlen! 13 10 /07
            Set /A "MRow=BotRow+5"
            Set "MClick=None"
        )
    ) Else If %input% EQU 0 (rem.Timed out with no interation - not enabled
        Set /A "MRow=BotRow+5"
        Set "MClick=None"
        Show "timed out at %time%" 13 10
    ) Else (rem.Mouse button clicked
        Set /A "input=-input, Mrow=input >> 16, Mcol=input & 0xFFFF"
        if !Mcol! LSS 32768 (
            CursorPos 0 -1
            Set /A "CSlen=WindowCols-32"
            ColorShow /07 "LEFT button click at row !MRow!" 32x!CSlen! 13 10
            Set "MClick=Left"
        ) Else (
            Set /A MCol-=32768
            CursorPos 0 -1
            Set /A "CSlen=WindowCols-31"
            ColorShow /07 "RIGHT button click at row !MRow!" 32x!CSlen! 13 10
            Set "MClick=Right"
        )
    )

    If /I "%MClick%" EQU "Left" (CursorPos 0 -1&Show "Mouse Left-click at Row %MRow%, Col %MCol%" 13 10)
    Goto :InLoop
:Escape
    Exit /B

John A.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#3 Post by thefeduke » 17 Nov 2016 15:03

The .zip file in the first post has been revised with a ReadMe and better examples.

John A.

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#4 Post by Aacini » 17 Nov 2016 16:46

You didn't explained what exactly the problem is... I did some GetInput.exe tests with "/T millisec" option at the command-line and it worked as expected: when no input, the program ends at the given lapse and return a zero; if a keyboard or mouse input is given before the timeout, the program ends and correctly report the event.

I run your script and realized that in the first loop the mouse clicks are not reported. I modified the /T 0 number for values every time larger and quickly tapped a mouse button until the mouse clicks started to be reported. Then, I reviewed the source code of GetInput.asm program (that I wrote more than 2 years ago) and it looks correct: the delay is done via "WaitForSingleObject( hInput, dwMilliseconds )" and the input events are read with "ReadConsoleInput( hInput, ADDR lpBuffer, 1, ADDR lpEvents )". It seems that mouse click events don't stay in the console input buffer in the same way as the keyboard input events, but before I investigate this matter a point must be cleared.

A running Batch file is not event driven, but GetInput.exe seems to do that: you execute GetInput.exe and the Batch file stop at that point, but as soon as an input is made, GetInput.exe ends and the Batch file continue. If you try to write a loop controlled by mouse clicks (read via GetInput), then the program will always have problems derived by the slowness of Batch file processing...

Perhaps if you explain what exactly you try to do we could find another solution. Please, do not say: "Do the same thing of choice command"; such "description" say nothing at all!

Antonio

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#5 Post by misol101 » 17 Nov 2016 20:36

I don't know how Aacini's program GetInput works, but I changed your test script to use my program "cmdwiz" with the "getch_and_mouse" operation instead.

I removed the first loop as it seemed redundant and go straight to "NextLoop".

I *think* this behaves the way you want it, i.e it reports key presses and left and right mouse clicks and their locations, and after 9 seconds it terminates. (Note: at the moment it terminates after 9 seconds even if you have pressed a mouse button. I guess you would want to jump out of the loop when pressing a mouse button, but this is just a test, so... I put commented-out goto statements there to use anyway)

Also note that, like Getinput, "cmdwiz getch_and_mouse" supports a timeout value. However, for your purposes it's largely useless because:
1. cmdwiz getch_and_mouse also reports mouse movements, even when no mouse button is pressed
2. As long as the mouse pointer is inside the cmd window, periodic mouse events are received even when mouse is not moving

Instead, I keep track of time using "cmdwiz gettime" inside the loop.

Note that I still use a timeout (1000) for "cmdwiz getch_and_mouse". This is because if you don't, the operation will wait forever IF the mouse pointer is outside the cmd window.
Also note I use "cmdwiz setquickedit 0". If quickedit is enabled, mouse activity may sometimes result in starting a quickedit marking operation instead of reporting back to cmdwiz.

Code: Select all

@Echo Off&SetLocal EnableDelayedExpansion
    Set "windowCols=80"
    CLS
    Echo(A few Fields in row 00
    Echo(Row 1
    Echo('Esc' to terminate.
    Echo(
    Echo(Row # 4
    Echo(
    Echo(Use the keyboard or mouse now.

    set /a TIMEOUT=9000
    cmdwiz gettime & set /a STARTTIME=!errorlevel!
    cmdwiz setquickedit 0

    CursorPos&Set /A "BotRow=((!errorlevel!>>16)&0xFFFF)-2, MsgRow=BotRow+3"
::  Interpret moused location using AuxProgram: cmdwiz
:InLoop
    CursorPos 0 %MsgRow%
    cmdwiz getch_and_mouse 1000 > mouse_out.txt

    for /F "tokens=1,3,5,7,9,11,13 delims= " %%a in (mouse_out.txt) do set EVENT=%%a&set key=%%b&set MOUSE_EVENT=%%c&set MX=%%d&set MY=%%e&set LMB=%%f&set RMB=%%g
    if "%EVENT%" == "NO_EVENT" set key=0

    If %key% GTR 0 (
        CursorPos 0 -1
        If "%key%" EQU "27" (
            Set /A "CSlen=WindowCols-73"
            ColorShow / "Simulating a termination click because the '" "Esc"  "' key was pressed. " 32x!CSlen! 13 10 /07
            ColorShow / 32x%WindowCols% /
            Set "MRow=%BotRow%"
            CursorPos 0 %MsgRow%
            Goto :Escape
Rem.        Possible future use - filter numerals for multiple word selection
        ) Else (
            Set /A "CSlen=WindowCols-18"
            ColorShow / "A key, loosely interpreted as the '" %key%  "' key was pressed. " 32x!CSlen! 13 10 /07
            Set /A "MRow=BotRow+5"
        )
    )
    if "%LMB%"=="1" (
        CursorPos 0 -1
        Set /A "CSlen=WindowCols-32"
        ColorShow /07 "LEFT button click at row !MY!  " 32x!CSlen! 13 10
        Show "Mouse Left-click at Row %MY%, Col %MX%  " 13 10)
        ::goto Escape
    )
    if "%RMB%"=="1" (
        CursorPos 0 -1
        Set /A "CSlen=WindowCols-31"
        ColorShow /07 "RIGHT button click at row !MY!  " 32x!CSlen! 13 10
        Show "Mouse Right-click at Row %MY%, Col %MX%  " 13 10)
        ::goto Escape
    )
   
    cmdwiz gettime & set /a ELAPSEDTIME=!errorlevel!-%STARTTIME%
    if %ELAPSEDTIME% gtr %TIMEOUT% (
        Set /A "MRow=BotRow+5"   
        Show "Timed out at %time%, defaulted to Row !MRow!" 13 10
        goto Escape
    )
 
    Goto :InLoop
:Escape
    del /Q mouse_out.txt
    Exit /B


Edit: I'm saving a file called mouse_out.txt to the current folder. In a real script you would want to save that file to a %TEMP% location instead.

Edit 2: as for the ":Basic" loop that I removed, a timeout value of 0 to getch_and_mouse will give similar headaches to what Aacini described in his post. You need to use higher timeout values.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#6 Post by thefeduke » 17 Nov 2016 22:38

Thank you for looking at this for me.
Aacini wrote:It seems that mouse click events don't stay in the console input buffer in the same way as the keyboard input events, but before I investigate this matter a point must be cleared.
It seems that before anything, I had to solve a very basic problem, as evidenced by:

Code: Select all

F:\John 16GB Px\Scripts\AuxPrograms>where /R F:\ /t getinput
      1536    2/4/2014    6:53:48 PM  F:\John 16GB Px\Script
      3072    3/5/2014    7:59:46 PM  F:\John 16GB Px\Script
      3072    3/5/2014    7:59:46 PM  F:\John 16GB Px\Script
      3072    3/5/2014    7:59:46 PM  F:\John 16GB Px\Zani D
I was not using your distributed version. My experiments are going better, now that I have one that recognizes the switch in the first place. I think that I picked that one up from a old topic where you checked for its presence and rebuilt it if it could not be found.

As for the vague description, I was thinking of adding an option for a default selection if there were no action by the time that an optional timeout expired.

I did find an interaction with Quick Edit that prevents mouse clicks from being recognized that I had not experience before using the /T switch in GetInput. Once the window is opened with that property checked or unchecked, it has a memory that reverts to that state, without regard to manipulation by changing it with properties or cmdwiz in batch. just running a command can reset it, but I don't know exactly how. The uploaded version does not seem to be affected.

Thank you for your help.

John A.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#7 Post by thefeduke » 17 Nov 2016 23:07

Thank you for taking the trouble.
misol101 wrote:I removed the first loop as it seemed redundant and go straight to "NextLoop".
.....
However, for your purposes it's largely useless
.....
Also note I use "cmdwiz setquickedit 0". If quickedit is enabled, mouse activity may sometimes result in starting a quickedit marking operation instead of reporting back to cmdwiz.
.....
Edit 2: as for the ":Basic" loop that I removed, a timeout value of 0 to getch_and_mouse will give similar headaches to what Aacini described in his post. You need to use higher timeout values.
The redundant loop was just there to see if anything at all worked before I attempted decision-making and the timeout value was of no real consequence. For my purposes, I agree, but useless is too strong a word.

I am still troubled by quickedit. Please see my previous post to Aacini. Under the right conditions, the properties were used to uncheck the box and running getquickedit reported it on and back to properties it was indeed on. I set it off with setquickedit and lo and behold running getquickedit turned it on. It's magic.

John A.

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#8 Post by Aacini » 18 Nov 2016 18:48

I created a .zip file with all auxiliary .exe programs and companion text files and attached it to the first post in auxiliary .exe programs thread; I suggest you to download such file so you have the current version of GetInput.exe.

GetInput.exe program turn off QuickEdit, Ctrl-C and LineInput modes at start and recover the original settings at end, so it doesn't require any manual adjustment on this point.

The CHOICE /D switch requires that the default be one of the given options, so you can not distinguish a timeout from the default option. GetInput.exe return zero when timeout, so you may choose if the timeout imply a default option or another different action. For example:

Code: Select all

@echo off

cls
echo                                    ÉÍÍÍÍÍËÍÍÍÍÍ»
echo                                    º     º     º
echo Select an option via mouse click:  º No  º Yes º
echo                                    º     º     º
echo                                    ÈÍÍÍÍÍÊÍÍÍÍͼ
echo/

GetInput /T 9000 "NY" /M  36 1 40 3  42 1 46 3
if %errorlevel% equ 0 (
   echo 9 seconds timeout!
) else if %errorlevel% equ 1 (
   echo No...
) else if %errorlevel% equ 2 (
   echo Yes!
)

Antonio

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

#9 Post by thefeduke » 19 Nov 2016 01:48

Aacini wrote:.....
I suggest you to download such file so you have the current version of GetInput.exe.
.....
The CHOICE /D switch requires that the default be one of the given options, so you can not distinguish a timeout from the default option. GetInput.exe return zero when timeout, so you may choose if the timeout imply a default option or another different action. For example:
I had resolved my version problem and am working from a library that I downloaded in Sept. Thank you for the example. I see what you mean, if I did this:

Code: Select all

GetInput /T 9000 /I "123MNY" /M  37 1 41 3  28 1 32 3 43 1 47 3 46 1 53 3 
only codes 5 and 6 are unique as only characters, the 123 characters are place holders for the mouse, so that 4 has a shared meaning the is the same for click or keyboard.

My intention is to assign a row number as a default selection and to use the timeout to simulate the results of a mouse-click on that row and then allow the existing structure to run its course. That fits into my philosophy of avoiding action hard-coded analysis of multiple return codes, based on one character choices. Rather than a optional arguments like the /T and /D of CHOICE, why not continue to let the data define the menu? Something like

Code: Select all

Rem.Timeout nnnnn Default rrr
as the last line of the input would be visible in the view, execute harmlessly as a remark if clicked to run and be easily parsed into Set "TO=/T nnnnn" for a GetInput %TO% command.

Aacini wrote:GetInput.exe program turn off QuickEdit, Ctrl-C and LineInput modes at start and recover the original settings at end, so it doesn't require any manual adjustment on this point.
This is still a problem area for me. I have touched on this in a couple of posts, but now I have some experimental results to narrow the problem. Someone else may understand under the cover, but I can only document the behavior. I start with two shortcuts to the Command Prompt. I set the QuickEdit property of one OFF and the other ON before opening either window. The properties of the newly opened windows are as expected. Dragging the left mouse button is also a good indication. If you change the QuickEdit property of each window to its opposite, again everything appears as expected. The ugliness begins if you run find /?. Both windows have reverted to their newly opened state. Some other commands also wreak this havoc: FINDSTR, cmdwiz getQuickEdit and likely others. Remarkably, cmdwiz setquickedit does its function, but just the act of checking with cmdwiz getquickedit has a chance of flipping the setting depending on the originally opened state.

What does it all mean? Are there two sets of properties? The real boss comes out of hiding when angered? All of this means absolutely nothing to GetInput and MChoice as long as the /T switch of Getinput is not used. Otherwise my mouse is preempted by QuickEdit only if the window was originally opened with QuickEdit set ON. I cannot click, but I can cut and paste well. I am:

Code: Select all

 INFO.BAT version 1.2
--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [Version 10.0.14393]
Product name           :  Windows 10 Home, 64 bit
Performance indicators :  Processor Cores: 2      Visible RAM: 7951624 kilobytes

Date/Time format       :  (mm/dd/yy)  Sat 11/19/2016   2:39:08.06
__APPDIR__             :  C:\WINDOWS\system32\
ComSpec                :  C:\WINDOWS\system32\cmd.exe
PathExt                :  .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Extensions             :  system: Enabled   user: Enabled
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  en-US       Code Pages: OEM  437    ANSI 1252
DIR  format            :  11/13/2016  07:10 PM       419,430,400 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes

                          Missing from the tool collection:  debug

John A.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#10 Post by misol101 » 19 Nov 2016 03:10

I don't know about those quickedit problems. All I'm doing in "cmdwiz getquickedit" is call GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &fdwMode). So unless that Windows API is messed up somehow I don't have an explanation.

GetInput.exe program turn off QuickEdit, Ctrl-C and LineInput modes at start and recover the original settings at end, so it doesn't require any manual adjustment on this point.

I don't think this is enough though, you need to also disable quickedit when GetInput is not running (with cmdwiz setquickedit or similar), otherwise if quickedit is enabled a mouse click could possibly happen just before or just after GetInput runs, in which case you would get into quickedit marking mode (which you can visibly see).

Edit: the above is true in a loop scenario such as your test script, but I guess your end result script MChoice won't have loops if the GetInput /T switch works properly, so then it won't be a problem and you can ignore what I wrote above

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#11 Post by thefeduke » 19 Nov 2016 15:09

Mikael,
misol101 wrote:So unless that Windows API is messed up somehow I don't have an explanation.
Here is the briefest way to demonstrate the behaviour that I tried to explain in narrative, not in code. I ran this script in two different windows:

Code: Select all

@Echo Off
CmdWiz SetQuickEdit 0
Echo(Just ran SetQuickEdit 0
CmdWiz GetQuickEdit
Echo(rc from GetQuickEdit: %ErrorLevel%
CmdWiz SetQuickEdit 1
Echo(Just ran SetQuickEdit 1
CmdWiz GetQuickEdit
Echo(rc from GetQuickEdit: %ErrorLevel%
and got these results:

Code: Select all

Just ran SetQuickEdit 0
rc from GetQuickEdit: 1
Just ran SetQuickEdit 1
rc from GetQuickEdit: 1

Code: Select all

Just ran SetQuickEdit 0
rc from GetQuickEdit: 0
Just ran SetQuickEdit 1
rc from GetQuickEdit: 0

John A.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#12 Post by misol101 » 19 Nov 2016 19:30

No clue to be honest, quite strange. It produces 0,0,1,1 here, like it should (Win 7). Does it actually behave like what GetQuickEdit reports? (for example in your second example, is quickedit actually off after the script finishes?)

Edit: runs as expected on my Windows 8 machine too, so yeah, no clue really what's going on over there :)
Last edited by misol101 on 20 Nov 2016 06:37, edited 1 time in total.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#13 Post by thefeduke » 19 Nov 2016 23:45

misol101 wrote:No clue to be honest, quite strange. It produces 0,0,1,1 here, like it should (Win 7). Does it actually behave like what GetQuickEdit reports? (for example in your second example, is quickedit actually off after the script finishes?)
There is a reply that I can work with. All experiments with a script peppered with PAUSEs and directly from the command line allow Quick Edit functions consistent with what GetQuickEdit reports. I no longer have a Windows 7 system. My Windows 10 systems are based on Win8, Win7 64-bit and Win 7 32-bit. GetQuickEdit consistently reports the Quick Edit status when the window first opened and then actually changes the behavior of the window to that reported state. I get exactly the same effect as running FINDSTR /?. Since GetInput.exe acts the same with the /T switch and flawlessly without. I'll just check the return code and activate /T appropriately, based on a Windows 10 internal difference.

My question in the second post is now resolved to my satisfaction All I need now is any feedback about what I did roll out in the first post, while I work on Version 0.1 . Execution of the selected line is working and I am polishing up this timeout option. Thanks to Antonio and Mikael for your comments.

John.

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#14 Post by Aacini » 20 Nov 2016 12:23

thefeduke wrote:My intention is to assign a row number as a default selection and to use the timeout to simulate the results of a mouse-click on that row and then allow the existing structure to run its course.

GetInput return zero when a timeout occur as I said before, so such zero is not related to anyone of the options. You may link the zero to anything you want via additional code (independant of GetInput operation).

thefeduke wrote:That fits into my philosophy of avoiding action hard-coded analysis of multiple return codes, based on one character choices. Rather than a optional arguments like the /T and /D of CHOICE, why not continue to let the data define the menu?

I am afraid I don't understand what you mean, but I think the code below is an example of "avoid action hard-coded analysis of multiple return codes". In this program the actions are not hard-coded, but defined as data in an array that may also be read from a file; note that this method have no relation to GetInput, so it may also be used on values read by CHOICE, or SET /P commands. The positions of the mouse selection rectangles are not hard-coded either, but calculated (and modified) at run-time, and the "default timeout selection" is assigned to the center rectangle.

Code: Select all

@echo off

mode con: cols=80 lines=39
setlocal EnableDelayedExpansion
set "action[0]=goto Timeout"
set "action[1]=set /A Top-=^!^!Top*2"
set "action[2]=set /A Left-=^!^!Left*3"
set "action[3]=set /A Left-=(Left-58>>31)*3"
set "action[4]=set /A Top-=(Top-25>>31)*2"
set "action[5]=goto Terminate"

set "SP= "
for /L %%i in (1,1,6) do set "SP=!SP!!SP!"
set F2=201 206 188 200
set F3=206 187 188 200
set F4=206 206 188 200
set /A Left=0, Top=0

:loop
set /A L1=Left+6, T1=Top, L2=Left, T2=T1+4, L3=L1+6, T3=T1+4, L4=L1, T4=T3+4
set "M="
for /L %%i in (1,1,4) do (
   set /A R%%i=L%%i+6, B%%i=T%%i+4,  L=L%%i+1, T=T%%i+1, R=R%%i-1, B=B%%i-1
   set "M=!M! !L! !T! !R! !B!"
)
set /A L=L1+1, T=T2+1, R=R1-1, B=B2-1, Tp=Top+2
set "M=%M% %L% %T% %R% %B%"

(
cls
for /L %%i in (1,1,%Tp%) do echo/
echo !SP:~0,%Left%!         UP
echo/&echo/&echo/
echo !SP:~0,%Left%! LEFT    OK  RIGHT
echo/&echo/&echo/
echo !SP:~0,%Left%!        DOWN
for /L %%i in (1,1,4) do ColorBox !L%%i! !T%%i! !R%%i! !B%%i! /D !F%%i!
)

rem                UP  LEFT RIGHT DOWN ENTER
GetInput  /T 9000  294 293  295   296  13    /M %M%
!action[%errorlevel%]!
goto loop

:Timeout
echo/&echo/
echo Timeout...
:Terminate
echo/&echo/
echo You selected this position


thefeduke wrote:
Aacini wrote:GetInput.exe program turn off QuickEdit, Ctrl-C and LineInput modes at start and recover the original settings at end, so it doesn't require any manual adjustment on this point.

This is still a problem area for me. I have touched on this in a couple of posts, but now I have some experimental results to narrow the problem. Someone else may understand under the cover, but I can only document the behavior. I start with two shortcuts to the Command Prompt. I set the QuickEdit property of one OFF and the other ON before opening either window. The properties of the newly opened windows are as expected. Dragging the left mouse button is also a good indication. If you change the QuickEdit property of each window to its opposite, again everything appears as expected. The ugliness begins if you run find /?. Both windows have reverted to their newly opened state. Some other commands also wreak this havoc: FINDSTR, cmdwiz getQuickEdit and likely others. Remarkably, cmdwiz setquickedit does its function, but just the act of checking with cmdwiz getquickedit has a chance of flipping the setting depending on the originally opened state.

What does it all mean? Are there two sets of properties? The real boss comes out of hiding when angered? All of this means absolutely nothing to GetInput and MChoice as long as the /T switch of Getinput is not used. Otherwise my mouse is preempted by QuickEdit only if the window was originally opened with QuickEdit set ON. I cannot click, but I can cut and paste well.


Well, if this involved description means that "GetInput.exe fail when the cmd.exe window have the QuickEdit property set to ON and the /T switch is used", then YOU ARE RIGHT! :shock: I confirmed this behavior :? , so I carefully reviewed the description of SetConsoleMode Win-32 API function I used to develop this program and I can NOT found any error in my code! It seems that there are certain status combinations that are not documented. Then, I ignored the official documentation and completed some tests until I discovered that it is necessary to turn off all status (excepting ENABLE_MOUSE_INPUT) in order for this method to work: SetConsoleMode( hConsoleHandle, ENABLE_MOUSE_INPUT + ENABLE_EXTENDED_FLAGS ). After that, GetInput worked correctly always, don't matters the previous QuickEdit status.

I updated the GetInput.exe version in the .zip file at the auxiliary .exe programs post; I suggest you to delete your GetInput.exe file(s) and download the .zip file again. Please, post the results with the new version.

Antonio

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Mouse-Selectable Menu from a data file - a/la CHOICE

#15 Post by thefeduke » 21 Nov 2016 01:43

Aacini wrote:
thefeduke wrote:My intention is to assign a row number as a default selection and to use the timeout to simulate the results of a mouse-click on that row and then allow the existing structure to run its course.

GetInput return zero when a timeout occur as I said before, so such zero is not related to anyone of the options. You may link the zero to anything you want via additional code (independent of GetInput operation).
It seems that we are in complete agreement here. Thank you for the encouragement.
Aacini wrote:
thefeduke wrote:That fits into my philosophy of avoiding action hard-coded analysis of multiple return codes, based on one character choices. Rather than a optional arguments like the /T and /D of CHOICE, why not continue to let the data define the menu?

I am afraid I don't understand what you mean
Because my approach is let the data define the menu I had no interest (in this particular application) in the /I "Chars" keycode... options of GetInput. One still needs to code an action plan for each return code. Your example is dynamic in the values for the five areas but it is programmed specifically for those five. Consider adding it to you Aux examples. It seemed far less overwhelming than snake.bat. You already know why I was attracted to the Timeout option. More inspiration: Those /M boxes might be less clumsy than what I did for the non-data selections, like the Quit line.
Aacini wrote:I updated the GetInput.exe version ... Please, post the results with the new version.
Thank you for being so tenacious and responsive, especially after I had already "cried wolf" once when it was my error. I am cursed in creating such "rare" isolated circumstances. I am happy to report that my results were what I had hoped and you had expected.

An image of the output screen for this test has replaced my original output example in the first post of this topic.

John A.

Post Reply