Mouse Hovering in Batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: Mouse Hovering in Batch

#16 Post by misol101 » 21 Dec 2016 19:44

Aacini:

That's a bit of a strange definition, but ok, whatever Google says...

It would be pretty easy to make these "selection boxes" in the batch script itself. Secondly, what are you going to do if you want support for hovering over circular selection "boxes", or selection boxes with rounded corners, or if you want something else to happen when you hover except changing colors, or whatnot. I'm afraid you may have to go back to cmdwiz :)

But then again, it's good this thread got you working a bit... add circular "selection boxes" while you're at it :mrgreen:

On a more serious note, I'd say cmdwiz gives more freedom, while your program makes things quite a bit easier.
Last edited by misol101 on 22 Dec 2016 15:24, edited 1 time in total.

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Mouse Hovering in Batch

#17 Post by Sounak@9434 » 21 Dec 2016 23:14

@misol101
Yes I think cmdwiz gives more freedom in use.

@Aacini
As all the other tools made by you, getinput.exe is very fast too. Hoping for a release of version 1.3 . I replied on your post too.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Mouse Hovering in Batch

#18 Post by aGerman » 24 Dec 2016 07:21

How would you process mouse hovering in a batch code? Batch isn't event controlled. Every utility that waits for mouse input is blocking the batch execution. Your best bet is a non-blocking utility that immediately returns the current mouse position. Call it whenever you want to know where the mouse pointer is. Probably you have to write your code as some kind of polling loop or message loop where you permanently check some parameters returned by the external utilities and react accordingly.
mousepos.zip
(7.65 KiB) Downloaded 490 times

Also forget about something like "round buttons". The console buffer is devided into character cells because cosole windows are text-based. How many values do you think you have to check in your batch code in order to distinguish mouse positions inside or outside of the round buttons edge?
Don't try to twist a console window to a GUI. You won't succeed.

Steffen

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Mouse Hovering in Batch

#19 Post by Sounak@9434 » 24 Dec 2016 08:09

aGerman wrote:Also forget about something like "round buttons". The console buffer is devided into character cells because cosole windows are text-based. How many values do you think you have to check in your batch code in order to distinguish mouse positions inside or outside of the round buttons edge?

Unfortunately what you said is true that just to add round button support to the console window we have to check loads of values. But still,
aGerman wrote:Don't try to twist a console window to a GUI. You won't succed.

I'm no one to say this but still you should not say won't succed. It may be extremely tough but maybe not totally impossible.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Mouse Hovering in Batch

#20 Post by aGerman » 24 Dec 2016 08:37

Sounak@9434 wrote:It may be extremely tough but maybe not totally impossible.

Actually I'm not saying that it would be impossible. What I'm saying is that even if you have collected all those utilities that you need, you would still have to call them from within a batch code. As I told you in your other thread - permanently creating new processes in a loop is what kills the performance. At the end you would have a working GUI but it's unusable because it takes ages to wait for the processes and to evaluate all their outputs.

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Mouse Hovering in Batch

#21 Post by Sounak@9434 » 24 Dec 2016 09:08

aGerman wrote:
Sounak@9434 wrote:It may be extremely tough but maybe not totally impossible.

Actually I'm not saying that it would be impossible. What I'm saying is that even if you have collected all those utilities that you need, you would still have to call them from within a batch code. As I told you in your other thread - permanently creating new processes in a loop is what kills the performance. At the end you would have a working GUI but it's unusable because it takes ages to wait for the processes and to evaluate all their outputs.

That's the main problem and really such a tough one. No matter which way is used to create a GUI it does take ages to put them all on console window and unfortunately makes the file almost unusable.
Thanks, Though I wouldn't stop and try to do things as much as the console can handle. Maybe someday there would be such an alternative of cmd.exe that can handle complex scripts and let us to build a GUI (like in java or by tkinter/pygame for python)

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Mouse Hovering in Batch

#22 Post by aGerman » 24 Dec 2016 09:33

Sounak@9434 wrote:Maybe someday there would be such an alternative of cmd.exe that can handle complex scripts and let us to build a GUI (like in java or by tkinter/pygame for python)

It does already exist. You can write scripts using PowerShell that have a real GUI instead of a console window. Recently MS decided to make PowerShell the default console on Win10.
https://blogs.windows.com/windowsexperi ... ZbGJpvg.97
Another step of gradually fading out cmd.exe and batch. I'm afraid in ten years only dinosaurs will remember batch :?

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Mouse Hovering in Batch

#23 Post by Sounak@9434 » 24 Dec 2016 10:11

aGerman wrote:It does already exist. You can write scripts using PowerShell that have a real GUI instead of a console window. Recently MS decided to make PowerShell the default console on Win10.
https://blogs.windows.com/windowsexperi ... ZbGJpvg.97
Another step of gradually fading out cmd.exe and batch.


I have learned a little(very little) of powershell. I know that it supports gui but what I'm saying as a replacement is that which commands have (almost)same syntax as cmd.exe
aGerman wrote:I'm afraid in ten years only dinosaurs will remember batch :?

Batch is the first programming language I learned(now I use python) and it's quite sad to let it go like that.
Hope there are intelligent dinosaurs that can make batch scripts.

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

Re: Mouse Hovering in Batch

#24 Post by misol101 » 24 Dec 2016 12:34

I like this discussion :)

Look, Steffen, I'm not really arguing here. Do I think a GUI in the cmd Window makes sense? No, not really. But what you can do and what you should do are not always the same :) Basically all my tools are written with some sort of gaming/demo purpose in mind. Does it make a lot of sense to make games and graphics demos in the cmd line window? No, not really. Again, can and should...

(paraphrased) How many values do you think you have to process... for round buttons?

You make it sound like this is rocket science. Take the center of each button, calculate distance to the current mouse position, compare this with the button radius. I could also think of a number of other ways to do this.

Anyway, merry Xmas and thanks for all the work you're putting into this forum!

TSnake41
Posts: 12
Joined: 17 Dec 2016 12:49

Re: Mouse Hovering in Batch

#25 Post by TSnake41 » 24 Dec 2016 15:35

To my mind, the future of the batch programming come to alternatives interpreters, because Microsoft seem dropping cmd.exe to give place at Powershell.

That's a problem to automate stuff, because Powershell looks like a over-complicated bash interpretor and alternatives interpreters are too lowly developped to fully replace cmd.exe.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Mouse Hovering in Batch

#26 Post by aGerman » 24 Dec 2016 17:03

misol101 wrote:Again, can and should...

I'm not a killjoy. Just wanted to face the facts. Of course it's fun to write batch games and stuff but some expectations will not be met :wink:

TSnake41 wrote:Microsoft seem dropping cmd.exe

I don't even believe that MS will remove cmd.exe and the related tools in the near future (some KB more or less on the drive don't really matter) but they try to bring PowerShell into focus and decrease the importance of Batch. Sooner or later they can remove the Batch tools if only a minority still uses them. Remember the actual purpose of Batch. It's a language to automate administrative and perseverative tasks. I talked to our administrators at work. All of them endorse MS's decision. They use PowerShell for years because it opened up the entire world of the .NET framework in a scripting language. Don't get me wrong, I don't want to sell PowerShell :lol: I don't use it and have only little experiences.

Merry Christmas
Steffen

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Mouse Hovering in Batch

#27 Post by Sounak@9434 » 25 Dec 2016 02:19

TSnake41 wrote:To my mind, the future of the batch programming come to alternatives interpreters, because Microsoft seem dropping cmd.exe to give place at Powershell.

That's a problem to automate stuff, because Powershell looks like a over-complicated bash interpretor and alternatives interpreters are too lowly developped to fully replace cmd.exe.

That's true. I have checked some like dos9 and console2 but something that can actually replace cmd.exe, no not any.
aGerman wrote:
TSnake41 wrote:Microsoft seem dropping cmd.exe

I don't even believe that MS will remove cmd.exe and the related tools in the near future (some KB more or less on the drive don't really matter) but they try to bring PowerShell into focus and decrease the importance of Batch. Sooner or later they can remove the Batch tools if only a minority still uses them.

Hope that microsoft will not remove them. Sometimes something is not a garbage just because that is old and less useable. Though in windows 10 microsoft has just done the opposite by making powershell the main terminal. I am not saying that powershell is bad but if microsoft is going to remove cmd and batch at least they deserve a better burial than a windows update.

Anyway Merry Christmas everyone.

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

Re: Mouse Hovering in Batch

#28 Post by misol101 » 25 Dec 2016 07:53

Sounak: Here's something you might like: Mouse buttons, with hovering, of any shape, with any effect! And it's fast too :)

You need: cdmgfx + cmdwiz

Here are some screenshots:

Image
Hovering over the middle button, hover effect: outline of circle, text shifts color

Image
Hovering first button, button changes color, text content is changed

Image
Third button has been selected

Code:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
cmdwiz setfont 2
set /a SCRW=120 & set /a SCRWW=!SCRW!*2
mode %SCRW%,70
cmdwiz setbuffersize %SCRWW% k
color 07
cls

set /a XP=7, YP=4, BUTTONWIDTH=38, ACCBW=0, CHAR=0, OFFCOL=9

set /a PX1=0+%XP%+%ACCBW%,PY1=0+%YP%,PX2=30,PY2=20, LX=11+%XP%+%ACCBW%,LY=10+%YP%, ACCBW+=%BUTTONWIDTH%, CHAR+=1
set B1="fbox 0 1 20 %PX1%,%PY1%,%PX2%,%PY2% & text 7 1 0 PICK_ME %LX%,%LY%"
set B1H="fbox 0 9 20 %PX1%,%PY1%,%PX2%,%PY2% & text f 9 0 YES_YES %LX%,%LY%"
set B1P="fbox 0 a 20 %PX1%,%PY1%,%PX2%,%PY2% & text f a 0 ALRIGHT %LX%,%LY%"
set /a PX1+=%SCRW%
set B1OFF="fbox %OFFCOL% 0 0%CHAR% %PX1%,%PY1%,%PX2%,%PY2%"

set /a PX1=15+%XP%+%ACCBW%,PY1=10+%YP%,PX2=15,PY2=10, LX=11+%XP%+%ACCBW%,LY=10+%YP%, ACCBW+=%BUTTONWIDTH%, CHAR+=1
set B2="ellipse 0 0 x %PX1%,%PY1%,%PX2%,%PY2% & fellipse 0 1 20 %PX1%,%PY1%,%PX2%,%PY2% & text 7 1 0 Option_2 %LX%,%LY%"
set B2H="fellipse 0 1 20 %PX1%,%PY1%,%PX2%,%PY2% & ellipse 9 0 db %PX1%,%PY1%,%PX2%,%PY2% & text f 1 0 Option_2 %LX%,%LY%"
set B2P="ellipse 0 0 x %PX1%,%PY1%,%PX2%,%PY2% & fellipse 0 a 20 %PX1%,%PY1%,%PX2%,%PY2% & text f a 0 Option_2 %LX%,%LY%"
set /a PX1+=%SCRW%
set B2OFF="fellipse %OFFCOL% 0 0%CHAR% %PX1%,%PY1%,%PX2%,%PY2%"

set /a PX1=15+%XP%+%ACCBW%,PY1=0+%YP%,PX2=0+%XP%+%ACCBW%,PY2=22+%YP%,PX3=30+%XP%+%ACCBW%,PY3=22+%YP%, LX=11+%XP%+%ACCBW%,LY=13+%YP%, ACCBW+=%BUTTONWIDTH%, CHAR+=1
set B3="poly 0 1 20 %PX1%,%PY1%,%PX2%,%PY2%,%PX3%,%PY3% & text 7 1 0 Option_3 %LX%,%LY%"
set B3H="poly 0 9 - %PX1%,%PY1%,%PX2%,%PY2%,%PX3%,%PY3% & text f 9 0 Option_3 %LX%,%LY%"
set B3P="poly 0 a 20 %PX1%,%PY1%,%PX2%,%PY2%,%PX3%,%PY3% & text f a 0 Option_3 %LX%,%LY%"
set /a PX1+=%SCRW%,PX2+=%SCRW%,PX3+=%SCRW%
set B3OFF="poly %OFFCOL% 0 0%CHAR% %PX1%,%PY1%,%PX2%,%PY2%,%PX3%,%PY3%"

call :PROCESS_HOVER_BUTTONS 3 %SCRW% RESULT

echo %RESULT%

endlocal
goto :eof


:PROCESS_HOVER_BUTTONS <nofButtons> <screenWidth> <returnValue>
if "%~3" == "" echo Insufficient parameters & goto :eof
cmdwiz getquickedit & set /a QE=!errorlevel!
cmdwiz setquickedit 0
cmdwiz showcursor 0
set /a NOFB=%1, SCRW=%2, HOVERINDEX=32, MX=-100, MY=-100

set OUTP=""
for /L %%a in (1,1,%NOFB%) do set OUTP="!OUTP:~1,-1! & !B%%aOFF:~1,-1! & !B%%a:~1,-1!"
cmdgfx %OUTP% p

:LOOP
for /L %%1 in (1,1,300) do if not defined STOP (
   cmdwiz getch_and_mouse>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 NEW_MX=%%d&set NEW_MY=%%e&set LMB=%%f

   if "!MOUSE_EVENT!"=="1" (
      set /a OR=0& (if !NEW_MX! neq !MX! set OR=1) & (if !NEW_MY! neq !MY! set OR=1) & if !OR!==1 (

         set /a CHKX=!NEW_MX!+%SCRW%
         cmdwiz getcharat !CHKX! !NEW_MY!
         set /a CHKCHAR=!errorlevel!

         if !CHKCHAR! geq 1 if !CHKCHAR! neq !HOVERINDEX! (
            if !CHKCHAR! leq %NOFB% for %%a in (!CHKCHAR!) do cmdgfx !B%%aH! p
            if !HOVERINDEX! leq %NOFB% for %%a in (!HOVERINDEX!) do cmdgfx !B%%a! p
            set /a HOVERINDEX=!CHKCHAR!
         )

         set /a MX=!NEW_MX!, MY=!NEW_MY!
      )

      if !LMB! == 1 if !HOVERINDEX! leq %NOFB% (
         for %%a in (!HOVERINDEX!) do set OUTP=!B%%aP!
         cmdgfx !OUTP! p
         set /a STOP=1, %3=!HOVERINDEX!
      )
   )

   if !KEY! geq 49 if !KEY! leq 57 (
      set /a KCHOICE=!KEY!-48
      if !KCHOICE! leq %NOFB% (
         for %%a in (!KCHOICE!) do set OUTP=!B%%aP!
         cmdgfx !OUTP! p
         set /a STOP=1, %3=!KCHOICE!
      )
   )

   if !KEY! == 27 set /a STOP=1, %3=0
)
if not defined STOP goto LOOP

del /Q mouse_out.txt>nul
cmdwiz setquickedit %QE%
cmdwiz showcursor 1


The routine PROCESS_HOVER_BUTTONS can be re-used as-is and does not need to be changed for other buttons. All you need to do is to set up the drawing operations for the buttons. Using three different shapes is just to show it's possible, but if e.g. all of the buttons were circular, then you could make another subroutine to create these from some simpe input like label and size, and call PROCESS_HOVER_BUTTONS after that.
The buttons can also be selected by pressing 1-9 on the keyboard. The index of the selected button is returned in third parameter.

How does it work? You define three drawing operations for each button, the normal, the hovered(H) and the pressed(P). In the simplest case you could use exactly the same coordinates/operation and just change colors. Here's the trick though: to work, this routine needs the buffer to be twice as big as the screen size (at least). You draw a fourth version of the button, the "mask", outside the visible area with a constant change in x, with a unique character (use 01 for button 1, 02 for button 2 etc). In the loop, I use cmdwiz getchar to check which char is touched by the mouse in the current mouse position+constant x.

This is a concept-thing, I'm not saying it's perfect and you might be able to find some unexpected behavior (e.g. hold down left mouse button and enter hover area=select button immediately)


Edit: if you want a more complex look for the buttons, you could use the cmdgfx "image" operation too and use three different pcx or gxy or txt files for the different states, possibly with a text on top. Just make sure you have a matching single-char mask of the shape offscreen
Last edited by misol101 on 16 Apr 2017 14:31, edited 4 times in total.

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Mouse Hovering in Batch

#29 Post by Sounak@9434 » 25 Dec 2016 08:15

misol101 wrote:Sounak: Here's something you might like: Mouse buttons, with hovering, of any shape, with any effect! And it's fast too :)

You need: cdmgfx + cmdwiz

I was actually working on this thing since last a few hours with cmdwiz's getch_and_mouse and cmdgfx. I drew a circle with lines not characters. I had some success but in pixel level the button changed color(by hovering) even though the mouse cursor was slightly away from the shape. It was quite slow too. Your solution solves this problem.
Thanks you very much.

EDIT: In my case I was inputting the values of all the cells in which a part of the circle is in, into some if...else commands.

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

Re: Mouse Hovering in Batch

#30 Post by misol101 » 25 Dec 2016 09:59

Small stability fix, updated script above. Would stop working if you scrolled to the right and started moving the mouse in the "off-screen" area

Post Reply