MOUSE()

Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4 Armite F4 ArmiteH7 Picomite CMM2

Syntax:
MOUSE(funct, channel)

Description:
Returns data from a Mouse controller supporting the Hobbytronic protocol. 'channel' is optional and is the I2C channel for the controller (defaults to 2, pins 27 and 28).

The mouse is interrogated using the MOUSE function
MOUSE(X [,channel]) 
 returns the X coordinate

MOUSE(Y [,channel])
 returns the Y coordinate

MOUSE(L [,channel])
eturns the status of the left button (1=pressed)

MOUSE(R [,channel]) 
 returns the status of the right button (1=pressed)

MOUSE(W [,channel]) 
 returns the status of the wheel click (1=pressed)

MOUSE(S [,channel])
to read the scroll wheel count

MOUSE(Z [,channel])
to both read it and zero the scroll wheel cont

MOUSE(D [,channel])
This allows you to detect a double click of the left mouse button and works for both the PS2 and Hobbytronic mice. 
The algorithm say the two clicks must occur between 100 and 500 milliseconds apart. The report via MOUSE(D) is then valid for 500mSec before it times out or until it is read.

The mouse is initialised by the CONTROLLER MOUSE command.

 'mouse and cursor test
 mp = 0
 CLS
 MODE 1,8
 GUI CURSOR ON

 CONTROLLER MOUSE OPEN mp, leftclick, rightclick

 PRINT "Mouse found is type ",MOUSE(t,0)
 PAUSE 1000
 CLS
 'I2C2 WRITE 41,1,2,28,10
 SETTICK 50, myint
 DO : LOOP UNTIL INKEY$ <> "" '
 GUI CURSOR OFF

 CONTROLLER MOUSE CLOSE mp

END
 
SUB myint
  GUI CURSOR MOUSE(x,mp),MOUSE(y,mp)
   PRINT @(10,10)MOUSE(x,mp);"  ";MOUSE(y,mp);"  ";MOUSE(s,mp);"  ";MOUSE(w,mp);"  "
   IF MOUSE(D,mp) THEN
   PRINT @(10,50)"Doubleclick"
   ELSE
   PRINT @(10,50)"            "
   ENDIF
END SUB
 '
SUB leftclick
  STATIC INTEGER n
  LOCAL INTEGER x=MOUSE(x,mp),y=MOUSE(y,mp)
  GUI CURSOR OFF
  GUI CURSOR ON 1,x,y, RGB(RED)
  n=n+1
  PRINT @(100,100)"left",n
END SUB
 '
SUB rightclick
  STATIC INTEGER n=0
  LOCAL INTEGER x=MOUSE(x,mp),y=MOUSE(y,mp)
  GUI CURSOR OFF
  GUI CURSOR ON 0,x,y
  n=n+1
  PRINT @(200,100)"Right",n
END SUB

Don't have the MOUSE function?

You can use this:

 ' ht_mouse test
 CLS
 MODE 1
 initmouse
 SPRITE LOAD "mouse.spr",1
 'pause 100
 DO
   readmouse
   TEXT 0,0,STR$(x,6,0," ")+STR$(y,6,0," ")+STR$(lb,2,0," ")+STR$(rb,2,0," ")+STR$(sb,2,0," ")+STR$(xs,4,0," ")+STR$(ys,4,0," ")+STR$(ss,6,0," ")
   SPRITE SHOW 1,x,y,1
   PAUSE 30
 LOOP UNTIL INKEY$ <>""
 SPRITE HIDE 1
 I2C2 CLOSE
 '
SUB initmouse
 I2C2 OPEN 100,1000
 I2C2 WRITE 41,0,3,20,INT(MM.HRES \ 256),INT(MM.HRES MOD 256)
 I2C2 WRITE 41,0,3,20,INT(MM.HRES \ 256),INT(MM.HRES MOD 256)
 I2C2 WRITE 41,0,3,22,INT(MM.VRES \ 256),INT(MM.VRES MOD 256)
 I2C2 WRITE 41,0,3,24,INT(MM.HRES \ 512),INT((MM.HRES\2) MOD 256)
 I2C2 WRITE 41,0,3,26,INT(MM.VRES \ 512),INT((MM.VRES\2) MOD 256)
 I2C2 WRITE 41,0,2,28,10
END SUB
 '
SUB readmouse
 DO
   I2C2 WRITE 41,1,1,0
   I2C2 READ 41,0,10,s$
   x=STR2BIN(UINT16,LEFT$(s$,2),big)
   y=STR2BIN(UINT16,MID$(s$,3,2),big)
   lb=ASC(MID$(s$,5,1))
   rb=ASC(MID$(s$,6,1))
   sb=ASC(MID$(s$,7,1))
   xs=STR2BIN(int8,MID$(s$,8,1))
   ys=STR2BIN(int8,MID$(s$,9,1))
   ss=ss+STR2BIN(int8,MID$(s$,10,1))
 LOOP UNTIL x>=0 AND x<MM.HRES AND y>=0 AND y< MM.VRES 'trap missreads
END SUB


Last edited: 03 January, 2021