Introduction MTB Statements File System Compiler Applications Reference Guide Index

Mouse Demo

This program draws a box on the screen, then waits for a mouse click to occur within the bounds of the box. The coordinates of all mouse clicks are displayed on the message line via the (WC) mnemonic.

  !----------------------  DATA DIVISION  -------------------------
  LENGTH 2 & LOCAL CLICK$                     ! Input variable
  LENGTH 2 & LOCAL MOUSECURSOR$               ! Mouse location
  LENGTH 1 & LOCAL MOUSECLICK$,MOUSESTATE$    ! Other mouse fields
  LENGTH 3.0 & LOCAL ROW, COLUMN              ! Mouse location

  !----------------------  FORMAT DIVISION  -----------------------

  MOUSE.INFO: FORMAT MOUSECURSOR$;MOUSECLICK$;MOUSESTATE$
  !
  ! Mouse info contains 4 binary bytes:
  ! Byte 1 = Horizontal mouse coordinate
  ! Byte 2 = Vertical mouse coordinate
  ! Byte 3 = Last mouse button state where any buttons were down
  ! Byte 4 = Current state of mouse buttons where:
  !          @01@ = Left button down
  !          @02@ = Right button down
  !          @04@ = Center button down

  !======================  PROCEDURE DIVISION =====================

  PRINT (0) (CS)                           ! Clear the screen
  PRINT (0) (Change colors="@07@","@70@","@00@","@00@","@00@")
  PRINT (0) (Draw box=10,5,20,10)          ! Draw box
  PRINT (0) (Hide cursor)                  ! Make cursor invisible
  PRINT (0) (Enhanced mouse on)            ! Open mouse driver
  PRINT (0) (Show mouse cursor)            ! Show mouse cursor

  !----------------------------------------------------------------

  TOP:  INPUT (0) CLICK$                   ! Wait for mouse click
        IF CLICK$ = "@00FE@" OR _          ! Mouse button down?
             CLICK$ = "@00FF@" THEN _     ! Mouse button up?
        GOTO CLICK                         ! Branch out of loop

        GOTO TOP                           ! Loop back
  !----------------------------------------------------------------

  CLICK: READ (0,MOUSE.INFO)               ! Read mouse data

         ROW=ASC(MOUSECURSOR$)-1           ! Determine row
         COLUMN=ASC(SUB(MOUSECURSOR$,2,1)) ! Determine column

         PRINT (0) (WC);"COLUMN=";COLUMN;"ROW=";ROW

         IF COLUMN GE 10 AND COLUMN LE 20  ! Click within the box?
            IF ROW GE 5  AND ROW LE 10
               GOTO QUIT                   ! If so, branch out
            ENDIF
         ENDIF

         GOTO TOP                          ! Otherwise, loop back

   !---------------------------------------------------------------

  QUIT: PRINT (0) (Mouse off)              ! Close mouse driver
        PRINT (0) (Show cursor)            ! Make cursor visible
        PRINT (0) (WC);"@00@"              ! Clear the message line

  RUN "QMONITOR"
  END
!


Mouse Driver