Simple Mouse Test

246 views
Skip to first unread message

Mel Smith

unread,
Jul 19, 2021, 11:12:05 AM7/19/21
to Harbour Users
For the last several days, I've been trying to test mouse movement on my laptop.

I have been using the mouse.prg that is in the \harbour\tests\ sub-dir.

I can (supposedly) move the mouse cursor programmatically around the screen by the  function mSetPos(nrow,nCol). When I exercise this command the functions mrow(), and mcol() react correctly and the mouse cursor position is supposedly moved. (A fragment of the test proggie is shown below)

However, I see *no* movement of the cursor on my screen ???  Am I misunderstanding this test ?

Because I have disabled my touchpad, and use a USB-connected Mouse, could this disrupt this test ??

Thanks for any help offered.
-Mel
 
***** fragment of my test *****
#include "inkey.ch"
#include "set.ch"

PROCEDURE Main()
   LOCAL lSavMCursor,lNewMCursor
   LOCAL nR := 5, nC := 38
   LOCAL nMROW,nMCOL
   setmode(25,80)
   SET(_SET_EVENTMASK,INKEY_ALL)

   SET CURSOR OFF
   CLS
   IF ! MPresent()
      ? " No mouse present !"
      QUIT
   ENDIF

   lSavMCursor := MSETCURSOR(.T.)

   @ 0, 0 TO MaxRow(), MaxCol() DOUBLE
   @ MaxRow() - 2,  0 TO MaxRow(), 18 DOUBLE
   @ MaxRow() - 1,  2 SAY "Y:"
   @ MaxRow() - 1, 10 SAY "X:"

   @ nR,  2 SAY "Mouse Type    :"

   @ nR, 18 SAY "Mouse System"

   @ MaxRow() - 2, 68 TO MaxRow(), MaxCol() DOUBLE
   @ MaxRow() - 1, 70 SAY "Exit"

   @ 10,  2 SAY " -- Checking  --"
   @ 11,  2 SAY "Window Boundaries :"
   @ 12,  2 SAY "Press/Release But.:"
   @ 13,  2 SAY "Double Click Left :"
   @ 14,  2 SAY "Double Click Right:"

   mSetPos(maxrow()-3,20)
   nMROW := MROW()
   nMCOL := MCOL()


   MUPDATE()

   // at this point I see the Mouse position has been updated at
   // the bottom left of the screen, but
   // my mouse cursor has *not* moved.
   // Why is this please ??

   inkey(0)


   SET CURSOR ON

   RETURN

STATIC FUNCTION MUPDATE()

   @ MaxRow() - 1,  4 SAY MRow() PICTURE "9999"
   @ MaxRow() - 1, 12 SAY MCol() PICTURE "9999"

   RETURN 0

***** end of fragment *****

 

Auge & Ohr

unread,
Jul 19, 2021, 4:54:52 PM7/19/21
to Harbour Users
hi,

you are using mSetPos() in Console Mode ... why not use GETLIST to re-position Cursor ?

if you want to do it in GUI Mode have a look at Snap2Crtl() in c:\MiniGUI\SAMPLES\BASIC\BUTTON_1\demo3.prg

Jimmy

mstuff kstuff

unread,
Jul 19, 2021, 10:35:54 PM7/19/21
to Harbour Users
Hi Mel,

Just to make things a little more complicated;

I did a inkey().exe that, I think worked with some older version of hb32 w/mingw and, now with version  Harbour 3.2.0dev (r1909261630) that I am using. The mouse is not recognized with a "i = inkey(0)" code.
Bummer.

#include "inkey.ch"
PROCEDURE MAIN()
  SET EVENTMASK TO (INKEY_ALL)
  i = INKEY(0)
  ? "i=" +LTRIM(STR(i))    // no response
  WAIT
RETURN

But, compiling and linking it with hb34 the mouse is recognized.

So, my preliminary guess would be that mingw is not recognizing the hbmk2.exe  -gui  setting as, the exe is now just a older console type of a dosbox.
I did try hb32 with the   -gui  setting and without it  just to make sure. Still, i = inkey(0) does not include mouse anything.

Try the the above with hb34.with the   -gui  setting and, it will work.
MikeK

mstuff kstuff

unread,
Jul 19, 2021, 11:02:12 PM7/19/21
to Harbour Users
OOps, I was premature in simplifying the above code.
The above doesn't work with hb34.
So here is my inkey().prg which does work with hb34 and, not with my version of hb32.

//inkey() (c) mjk
//
#include "inkey.ch"
PROCEDURE MAIN()                       // Inkey().prg or test1.prg
SETMODE(25,80)                         // sets the screen size (typical)
SET COLOR TO W+/N                      // sets the color (white on black)
SETCURSOR(2)                           // sets the cursor size
SET EVENTMASK TO (INKEY_ALL)           // set to read all the keys pressed
font = 'Lucida Console'                // sets the font and size
wvT_SETFONT("Lucida Console",16,8,0,,,,,3)  // 16,8 can be changed for the size

?
? " INKEY" +CHR(40) +CHR(41) +" W/mouse. hb32 default codepage. Esc exits"
? " This shows the number used for a key press or mouse key."
INKEY(0)                               // wait for a key press
I_n = 0
DO WHILE I_n = 0
 I_n = INKEY(0)                        // store the key press to I_n
 IF I_n = 1001                         // ? LASTKEY() would be the same
   ?
   @ 24,0 SAY ""                       // say nothing, move the cursor there
   ?? I_n, CHR(I_n),"mouse move"       // say it on the same line
   
/* for mel */
??mrow()
??mcol()
@mrow(),mcol() say "M"
inkey(0)
/* end for mel */

 ELSE
   ?
   ? I_n, CHR(I_n)                     // show the key number and the key result
 ENDIF
 IF I_n = 27
   ?
   ? I_n, "the escape key was pressed"
   WAIT "        press the enter to exit" to x
 ELSE
   I_n = 0                             // reset I_n to sty in the do loop
 ENDIF
ENDDO
RETURN nil

Mel Smith

unread,
Jul 19, 2021, 11:57:19 PM7/19/21
to Harbour Users
Hi Mike et al:
   I don't have a hb43 build available right now, and want to stick to HB 3.2 anyway.
   So, the above alternate solutions confuse me.
   Mike:  I compiled your proggie above (I had to go looking for WVT_SETFONT and found it). When I ran it, I was confused at the output and its late now, and I'm discouraged :(

   So, why is it so hard to view a mouse 'arrow' being moved around a screen programmatically.
   Why is there not a proggie that does this.  After all, *I* can move my mouse arrow manually, why can't I move it with a simple program ?
   Nitey-nite !

-Mel

Mel Smith

unread,
Jul 19, 2021, 11:59:13 PM7/19/21
to Harbour Users
btw, I added a -gui option to my .hbp file for mike's program.
-Mel

Mel Smith

unread,
Jul 20, 2021, 12:19:01 PM7/20/21
to Harbour Users
HI Jimmy:
   I don't have ....\basic\button_1\demo3.prg in my minigui package. I also did a text search for "snap2ctrl" in my minigui package. Found nothing.
-Mel

Pete

unread,
Jul 20, 2021, 3:47:23 PM7/20/21
to Harbour Users
Hi Mel,
On Tuesday, 20 July 2021 at 06:57:19 UTC+3 Mel Smith wrote:
   So, why is it so hard to view a mouse 'arrow' being moved around a screen programmatically.
I agree mouse is sometimes hard to view, but harbour is good  too!  rather more best than others (languages).
try the code below. in fact is your code, slightly modified:

---------------------------------------
/*
    mous.prg
    The (almost) everything about mous!
    compile hbmk2 mous.prg hbwin.hbc
*/
#include "inkey.ch"
#include "set.ch"
#pragma -w3
#pragma -es2
PROCEDURE Main()
   LOCAL nR := 5, nC := 10
   LOCAL nKey
   setmode(25,80)
    Set( _SET_EVENTMASK, HB_INKEY_ALL )
   Set( _SET_CURSOR, 0 )
    setcolor( "G+/N" )   
   CLS
   IF ! MPresent()
      ? " No mouse present !"
      QUIT
   ENDIF
   MSETCURSOR(.T.)
   @ 0, 0 TO MaxRow(), MaxCol() DOUBLE
   @ MaxRow() - 2,  0 TO MaxRow(), 18 DOUBLE
   @ MaxRow() - 1,  2 SAY "Y:"
   @ MaxRow() - 1, 10 SAY "X:"
   @ nR-3,  nC SAY "The everything about mous! [or the few, anyway] :-)]"
   @ nR,    nC SAY "do i hav a mouse? : " + iif( wapi_GetSystemMetrics( 19 ) > 0, "Yes", "Nope!" )
   @ nR+4, nC SAY "a mouse has wheel? : " + iif( wapi_GetSystemMetrics( 75 ) > 0 .OR. ;
                                                wapi_GetSystemMetrics( 91 ) > 0, "Yes, 1", "Nope!" )
   @ nR+2, nC SAY "a mouse haz butts? : " + iif( (nKey := wapi_GetSystemMetrics( 43 )) > 0 , "Yes, "+hb_ntos(nKey), "Not 1" )
   @ nR+6, nC SAY "am i left-handed? : " + iif( wapi_GetSystemMetrics( 23 ) > 0, "Yes, you are!", "No sir!" )
   @ nR+10,nC SAY "Press Esc or click [ Exit ] to get out!"

   @ MaxRow() - 2, 68 TO MaxRow(), MaxCol() DOUBLE
   @ MaxRow() - 1, 70 SAY "Exit"
   mSetPos(maxrow()-3,20)
   while (nKey := inkey()) <> 27
      MUPDATE()
      if mrow() >= MaxRow() - 2 .and. mcol() >= 68 .and. nKey == K_LBUTTONUP
         exit
      endif
   end
   Set( _SET_CURSOR, 1 )
   RETURN
STATIC PROCEDURE MUPDATE()

   @ MaxRow() - 1,  4 SAY MRow() PICTURE "9999"
   @ MaxRow() - 1, 12 SAY MCol() PICTURE "9999"
   RETURN

---------------------------------------

regards,
Pete


Mel Smith

unread,
Jul 21, 2021, 12:23:04 AM7/21/21
to Harbour Users
Hi Pete:
   In this loop below nothing happens. 'Click' to Exit doesn't work, only <Esc> gets me out of the loop
   No matter where I move the mouse cursor no change is seen in the update section.
   But, the system metrics show my mouse properly.
 I'm obviously missing something basic here.
-Mel


*******fragment showing the loop *****
while (nKey := inkey()) <> 27
      MUPDATE()
      if mrow() >= MaxRow() - 2 .and. mcol() >= 68 .and. nKey == K_LBUTTONUP   // no effect whatsoever
         exit
      endif
end
***** end of fragment *****

Mel Smith

unread,
Jul 21, 2021, 12:37:33 AM7/21/21
to Harbour Users
Hi Pete (again):
Here is my pete.hbp file contents below

***** contebts of pete.hbp *****
#pete.hbp
#=====
-strip
-info
-static
-st
-Lc:\mingw111\mingw32\lib;
-lxhb
-m
-map-
-workdir=c:\mgw\temp\
-rebuildall
-opete
harbour.hbx
hbwin.hbc
***** end of pete.hbp contents *****

Pete

unread,
Jul 21, 2021, 3:41:49 AM7/21/21
to Harbour Users
Hi Mel,
your .hbp file has a lot of not-really-needed things and lacks the most important: the .prg you try to compile.

please test this:
------------------------------------------------------------------
# Melmous.hbp

-gtwvt
-run
-oMel

# supposedly, mous.prg is the .prg with the code I posted in my previous post
mous.prg
hbwin.hbc

# end of .hbp
# save it and, assuming your harbour/mingw paths have been set correctly, in command line do: hbmk2 melmous
---------------------------------------------------------------------

you should see a retro `green/black`  screen with mouse coords rolling  on the bottom-left corner.
if not, something strange is happening with your mouse,  most probably not related with harbour.
(hope there isn't around any cat  meowing, badly scaring the poor micky! is it? :-)

regards,
Pete

Pete

unread,
Jul 21, 2021, 4:55:14 AM7/21/21
to Harbour Users
On Wednesday, 21 July 2021 at 07:23:04 UTC+3 Mel Smith wrote:
      if mrow() >= MaxRow() - 2 .and. mcol() >= 68 .and. nKey == K_LBUTTONUP   // no effect whatsoever

Ok then,  let's become a little more aggressive...
replace the line above with:

if mrow() >= MaxRow() - 2 .and. mcol() >= 68 .and. ( nKey > 1001 .AND. nKey < 1011 ) // trace the click of any mouse button


regards,
Pete

Mel Smith

unread,
Jul 21, 2021, 11:14:51 AM7/21/21
to Harbour Users
Hi Pete:
   It works now !!!
   It was the -gtwvt option that did the trick.  After placing that in my pete.hbp file, it worked immediately.
   Thank you very much !
   You may wish to view my bldapp.bat file (listed below) where all my apps are built successfully.
   Also, my prgs for any particular app are listed in a response file. For your mouse app, it is pete.rsp
   The app for the client I'm try to help has 80+ files in *his* response file.

   Anyway, I now can get back to helping *him* with *his* mouse problems. The key is 'probably' -gtwvt !!!
   So, thanks again for this key ingredient !

   -Mel

***** my bldapp.bat file contents below *****
@ECHO OFF
CLS

SET SAVPATH=%PATH%
IF ~%1==TESTMAIL SET HB_STATIC_OPENSSL=yes
IF ~%1==testmail SET HB_STATIC_OPENSSL=yes

IF ~%1==~ GOTO NOAPP
IF EXIST %1.hbp GOTO GOTHBP
GOTO NOHBP
:GOTHBP
REM Have to Ensure that MinGW Compiler is on path
SET PATH=C:\MINGW111\MINGW32\BIN;C:\harbour\BIN;C:\harbour\LIB;c:\CURL\LIB;

DEL %1.LOG
DEL %1.EXE
IF EXIST %1.EXE GOTO BADDEL

echo .
echo . Compiling / linking %1.prg
echo .
\harbour\BIN\HBMK2 @%1.hbp XHB.HBC @%1.RSP hbwin.hbc -plat=win -comp=mingw -workdir=\mgw\temp -rebuildall > %1.LOG 2>&1


IF EXIST %1.EXE GOTO GOODBLD
IF EXIST %1init.EXE GOTO GOODBLD
ECHO .
ECHO .
ECHO .  Failed to create executable.
ECHO .
ECHO . View %1.LOG to see what happened.
ECHO .
PAUSE
ECHO .
GOTO ENDJOB

:GOODBLD
ECHO .
ECHO . Build Was Successful. %1.exe was created
ECHO . View %1.LOG for info on Build
ECHO .
GOTO FINISH


:BADDEL
ECHO .
ECHO . Build Failed. Failed to delete old executable: %1.exe
ECHO . View %1.LOG for info on Build
ECHO .
GOTO FINISH

:NOAPP
ECHO .
ECHO . Argument 1 must be the root name of the 'App' to be built
ECHO .
PAUSE
GOTO FINISH

:NOHBP
ECHO .
ECHO . There is NO Harbour .HBP File to get options from
ECHO .
PAUSE
GOTO FINISH

:FINISH

:ENDJOB
SET PATH=%SAVPATH%
ECHO . Deleting the .map, .tds files ...
ECHO .
DEL *.MAP
DEL *.TDS

***** end of bldapp.bat *****

Mel Smith

unread,
Jul 22, 2021, 11:46:47 AM7/22/21
to Harbour Users
Hi Pete:
   My user (The Reverend Dr. Benson O. Amari in Nigeria) has asked me to relay his Thanks to You for your help in resolving his mouse problems in his massive budget program.
   For him and me, Thanks again !
-Mel

Mel Smith

unread,
Jul 22, 2021, 12:04:55 PM7/22/21
to Harbour Users
Hi Mike:
   With -gtwvt added as an option in my mike.hbp file, *your* proggie worked great too !
Thank you (for Rev Amari and myself)
-Mel


On Monday, July 19, 2021 at 9:02:12 PM UTC-6 mstuff...@gmail.com wrote:

Pete

unread,
Jul 22, 2021, 6:38:48 PM7/22/21
to Harbour Users
Hi Mel,

On Thursday, 22 July 2021 at 18:46:47 UTC+3 Mel Smith wrote:
   My user (The Reverend Dr. Benson O. Amari in Nigeria) has asked me to relay his Thanks to You for your help in resolving his mouse problems in his massive budget program.
   For him and me, Thanks again !
You are welcome! (you and your respectable user).
Glad to see that my humble contribution was helpful, although I think it is receiving
somewhat overmuch valuation. What is really interesting here, is to see the unexpected routes
the  knowldege (of any kind) can travel, some times. Impressive!

regards,
Pete
Reply all
Reply to author
Forward
0 new messages