DosTips.com

A Forum all about DOS Batch
It is currently 26 Sep 2017 13:49

All times are UTC-06:00




Post new topic  Reply to topic  [ 36 posts ]  Go to page Previous 1 2 3
Author Message
PostPosted: 16 Jan 2017 23:28 
Offline

Joined: 16 Dec 2016 22:31
Posts: 100
misol101 wrote:
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)

I found an (very)easy solution to this problem. Just add the value of LMB to another variable(In my case OLMB) and check "if !OLMB! == 0" then do the click action. Edited code here:-
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set OLMB=0
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 !OLMB! == 0 if !HOVERINDEX! leq %NOFB% (
         for %%a in (!HOVERINDEX!) do set OUTP=!B%%aP!
         cmdgfx !OUTP! p
         set /a STOP=1, %3=!HOVERINDEX!
      )
   )
   set OLMB=!LMB!

   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


Top
   
PostPosted: 17 Jan 2017 04:46 
Offline

Joined: 16 Dec 2016 22:31
Posts: 100
Eventually while creating the last code it hit me that in the very same way a dragging support could also be added. Check how is it?
Code: Select all
@echo off
setlocal enabledelayedexpansion
cmdgfx "box 0 b b0 29,9,17,2 & box 0 a 20 30,10,0,0 & box 0 c 20 45,10,0,0"
set boxp=30 10
:main
for /l %%1 in (1,1,300) do if not defined stop (
    for /f "tokens=1,2 delims= " %%2 in ("!boxp!") do set /a xa=%%2-1 & set /a xb=%%2+1 & set /a ya=%%3-1 & set /a yb=%%3+1
   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 M_EVENT=%%c&set MX=%%d&set MY=%%e&set LMB=%%f
   if !my! equ 10 if !mx! geq !xa! if !mx! leq !xb! if !my! geq !ya! if !my! leq !yb! (
      set drag=!drag:~-1!!LMB!
      if !drag! == 11 (
         for /f "tokens=1,2 delims= " %%5 in ("!boxp!") do (
            if !mx! neq %%5 (
               cmdgfx "box 0 b b0 29,9,17,2 & box 0 c 20 45,10,0,0 & box 0 a 20 !mx!,!my!,0,0" & set boxp=!mx! !my!
            ) ELSE (
               if !my! neq %%6 cmdgfx "box 0 b b0 29,9,17,2 & box 0 c 20 45,10,0,0 & box 0 a 20 !mx!,!my!,0,0" & set boxp=!mx! !my!
            )
         )
      )
   )
   if "!boxp!" == "45 10" set stop=1
)
if not defined stop goto main
echo Done.
pause>nul


Sounak


Top
   
PostPosted: 03 Feb 2017 01:22 
Offline

Joined: 02 May 2016 18:20
Posts: 303
Sounak: Sorry, didn't look into this before now. Well done, in both cases!


Top
   
PostPosted: 03 Feb 2017 03:21 
Offline

Joined: 16 Dec 2016 22:31
Posts: 100
misol101 wrote:
Sounak: Sorry, didn't look into this before now. Well done, in both cases!

Thanks :D .
I was quite wondering that if my last two posts were that booring to be replied :mrgreen:


Top
   
PostPosted: 15 Feb 2017 06:01 
Offline

Joined: 17 Dec 2016 12:49
Posts: 8
Hello, you can see my external command darkbox which (recently) supports mouse input (and hovering) and keyboard key in the same time.
See mouse(2).bat, knm(2).bat and it.bat in tests directory.

More information here : viewtopic.php?f=3&t=7718

Here is knm.bat explained :
Code: Select all
:: Darkbox launcher with input server support.
@Echo off
if defined __ goto :knm
set __=.
darkbox -i | %0 %* | darkbox
set __=
pause>NUL
goto :eof

:: Main function
:knm
:: Set color to 0, clear and hide cursor
echo -csh 0x00 0

:: Define variables
set K=N/A
set old_X=0
set old_Y=0

:loop

:: Get an input event throught stdin
set /p i=
:: Parse it
for /f "tokens=1,2,3,4" %%A in ("%i%") do (
    if %%A==m (
        set X=%%B
        set Y=%%C
        set C=%%D
        goto :draw_cur
    )
    if %%A==k (
        set K=%%B
        goto :draw_key
    )
)
goto :loop

:draw_cur
:: Mouse event
if %C% EQU 0 set C=F
echo -gcdw 0 0 0x9 "lastest key: %K%  " 0

:: Remove old mouse cursor (as a block) and draw the newest
echo -gca %old_X% %old_Y% 0x0f 32
echo -gcaw %X% %Y% 0x%C%0 32 0

set old_X=%X%
set old_Y=%Y%
goto :loop

:draw_key
:: Write at (0;0) the lastest key pushed.
echo -gcdw 0 0 0x9 "lastest key: %K%  " 0
goto :loop


Top
   
PostPosted: 15 Feb 2017 06:55 
Offline

Joined: 16 Dec 2016 22:31
Posts: 100
TSnake41 wrote:
Hello, you can see my external command darkbox which (recently) supports mouse input (and hovering) and keyboard key in the same time.
See mouse(2).bat, knm(2).bat and it.bat in tests directory

When I first saw knm(2).Bat I was like a :shock: :shock:
I mean, really, this much faster. Seems like a server is much more efficient in the matter of speed.
Great work TSnake41. Keep it up :wink:
Gonna use this in my games.

Sounak


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 36 posts ]  Go to page Previous 1 2 3

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited