ON MOUSE [LOCAL] example TOP OF THREAD

Discussions related to mouse, keyboard, fonts and Graphical User Interface
mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

ON MOUSE [LOCAL] example TOP OF THREAD

Post by mikeg »

Thanks to Patrick for helping me get this example of ON MOUSE [LOCAL] done

This will help in the case where a person wants to have ON MOUSE in a procedure or function. Very handy.

This is the current working example that also extracts the location of the mouse coordinates to xpos% and ypos% and passes the mouse button number to mb%

Code: Select all

      MODE 8
      PRINT"Start of program"
      REM: Set a mouse interrupt with ON MOUSE
      REM ON MOUSE: PRINT" ON MOUSE interrupt. Ending program with END. Bye":END:RETURN
      MOVE 100,100:PRINT "left click on the box and hold for 2 seconds"
      RECTANGLE 200,200,50,50
      REPEAT
        REM ON MOUSE  PROCmouse(@wparam%,@lparam%):RETURN :REM required
        PROCmoutest
        WAIT 5
      UNTIL FALSE
      END
      REM thanks to Patrick for finding the usage solution for ON MOUSE LOCAL
      DEFPROCmoutest
      REM Getting a response from a mouse interupt
      REM: Set a local mouse interrupt with ON MOUSE LOCAL
      ON MOUSE LOCAL:  E%=TRUE: RETURN:REM ON MOUSE LOCAL interrupt. Setting E% in order to exit loop":
      LOCAL E%,xpos%,ypos%,y%,mb%
      REM "Now entering a REPEAT loop testing variable E%"
      REPEAT
        WAIT 1
      UNTIL E% :REM LOCAL E% makes E%=0: if E% becomes -1 then it is TRUE (which explains E%=TRUE....hmmmm)
      xpos% = (@lparam% AND &FFFF) *2 - @vdu.o.x%
      ypos% = (@vdu%!212-1-(@lparam% >>> 16))*2 - @vdu.o.y%
      mb%=(@wparam%)
      REM now we check the area (200,200,250,250) for mouse presence and left button)
      IF xpos%> 200 AND ypos%>200 AND xpos%< 250 AND ypos%<250 AND mb%=1 THEN
        REM if a unique mouse button is held  it only will make 1 line
        LINE 250,250,250+RND(500),250+RND(500)
      ENDIF
      REM MOUSE STUFF ENDS HERE
      ENDPROC
      REM VERY NICE REFERENCE !!!!
Last edited by mikeg on Wed 19 Sep 2018, 01:33, edited 2 times in total.
Focus is on code subject. Feel free to judge the quality of my work.
p_m21987
Posts: 177
Joined: Mon 02 Apr 2018, 21:51

Re: ON MOUSE [LOCAL] (need help)

Post by p_m21987 »

I'm not sure what you're trying to do or exactly what trouble you're having with ON MOUSE. The examples you posted are a bit unclear.

If you're getting the "not in a subroutine" error, it might be that your ON MOUSE interrupt is being activated, and then you enter a procedure, and then you try to RETURN while still inside that procedure. That won't work, as far as I know. I think you need to exit out of the procedure and then RETURN.

So for example, this will not cause an error when you click the mouse:

Code: Select all

ON MOUSE: PROCtest: RETURN
REPEAT UNTIL FALSE
END
DEFPROCtest
ENDPROC
But this will cause an error when you click the mouse:

Code: Select all

ON MOUSE: PROCtest
REPEAT UNTIL FALSE
END
DEFPROCtest
RETURN
ENDPROC
I think this is correct, but if I'm wrong, please let me know.

I wrote this program while I was making sure I understood how ON MOUSE and ON MOUSE LOCAL work. Maybe you'll find it useful as an example of how to use ON MOUSE (LOCAL):

Code: Select all

      PRINT"Start of program"
      REM: Set a mouse interrupt with ON MOUSE
      ON MOUSE: PRINT" ON MOUSE interrupt. Ending program with END. Bye":END:RETURN
      PROCtest
      PRINT "Starting endless loop (REPEAT UNTIL FALSE)"
      REPEAT
        WAIT 1
      UNTILFALSE
      PRINT"Endo of program. This line should never be executed"
      END

      DEFPROCtest
      PRINT"Start of PROCtest"
      REM: Set a local mouse interrupt with ON MOUSE LOCAL
      ON MOUSE LOCAL: PRINT" ON MOUSE LOCAL interrupt. Setting E% in order to exit loop": E%=TRUE: RETURN
      LOCAL E%
      PRINT"Now entering a REPEAT loop testing variable E%"
      REPEAT
        WAIT 1
      UNTIL E%
      PRINT"End of PROCtest"
      ENDPROC
PM
mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

Re: ON MOUSE [LOCAL] (need help)

Post by mikeg »

Ok... this now works.. Thanks for the help. I will now tweak this to make it nice for others to learn. I am picking out some of the possible most handy commands that have no samples aside from a syntax and trying to make a special help reference for everyone. Ill mention you helped in the comments. Thanks Patrick.
Focus is on code subject. Feel free to judge the quality of my work.