Quantcast
Channel: Qbasic Forum RSS Feed (Replies Included)
Viewing all articles
Browse latest Browse all 25

Re: How to enable mouse in QBasic

$
0
0
I wrote the following program several years ago, and it is still the easiest way I have found to use the mouse in QBasic programs. Simply copy the Mouse sub-routine into a new program, then call it with a parameter of "1" to show the cursor, "2" to hide it, or "3" to read the mouse buttons & coordinates. To create your own programs, just replace the code in the "Main Program" section with your own code, and you're ready to go! Hope this helps, and feel free to contact me with
any questions. So long!


' "QBMouse.bas" Written 1999 by: Daryl R. Dubbs
'''''''''''''''''''''''''''''''' Initialize '''''''''''''''''''''''''''''''''
DECLARE SUB Mouse (Funk) ' Declare Mouse sub-program.
SCREEN 12 ' Graphics mode 12 (640 x 480 pixels, 16 colors)
Mouse 1 ' Show mouse cursor.

'''''''''''''''''''''''''''''''' Main Program '''''''''''''''''''''''''''''''
DO ' Start Main loop.
Mouse 3 ' Read mouse buttons & coordinates.
LOCATE 1, 1: PRINT "Buttons:"; B; "Horizontal:"; H; "Vertical:"; V
SELECT CASE B ' Which button is pressed?
CASE 1 ' Left button pressed.
Mouse 2 ' Hide mouse cursor.
Mouse 3 ' Read buttons & coordinates.
LINE STEP(0, 0)-(H, V), 14 ' Draw a yellow line.
Mouse 1 ' Show mouse cursor.
CASE 2 ' Right button pressed.
Mouse 2 ' Hide mouse cursor.
CLS ' Clear screen.
Mouse 1 ' Show mouse cursor.
CASE 3 ' Both buttons pressed.
EXIT DO ' Drop out of Main loop.
END SELECT ' End select block.
LOOP ' End Main loop.

'''''''''''''''''''''''''''''''' Exit Program '''''''''''''''''''''''''''''''
Mouse 2 ' Hide mouse cursor.
CLS ' Clear screen.
PRINT "Finito!" ' Print message.
SYSTEM ' End program.

'''''''''''''''''''''''''''''''' Mouse Sub-program '''''''''''''''''''''''''
' '
' This sub-program provides mouse support to QBasic programs. '
' It is called with one parameter, and performs as follows: '
' Mouse 1 ( Shows mouse cursor ) '
' Mouse 2 ( Hides mouse cursor ) '
' Mouse 3 ( Reads button status & co-ordinates ) '
' '
' Notes: '
' '
' This sub-program requires Microsoft's mouse driver ( Mouse.com ), '
' or an equivalent Dos-based mouse driver, which must be loaded and '
' running before use. '
' '
' Variables B, H & V are global, so be certain not to create any '
' other variables of the same name, or you must re-name these. '
' '
' Be sure to hide the mouse cursor before performing any graphics '
' function, or else any graphics under the cursor will be garbled. '
' '
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''
SUB Mouse (Funk) 'Define sub & parameter passed.
SHARED B, H, V 'Share variables with main sub.
STATIC Crsr 'Track whether Cursor is shown.
IF Funk = 1 THEN Crsr = 1 'Show Cursor.
IF Funk = 2 AND Crsr = 0 THEN EXIT SUB 'Don't hide Cursor more than once.
IF Funk = 2 AND Crsr = 1 THEN : Crsr = 0 'Hide Cursor.
POKE 100, 184: POKE 101, Funk: POKE 102, 0 'Poke machine code necessary for
POKE 103, 205: POKE 104, 51: POKE 105, 137 'using the mouse into memory
POKE 106, 30: POKE 107, 170: POKE 108, 10 'starting at offset 100 in the
POKE 109, 137: POKE 110, 14: POKE 111, 187 'current segment. This code is
POKE 112, 11: POKE 113, 137: POKE 114, 22 'then executed as a unit, via the
POKE 115, 204: POKE 116, 12: POKE 117, 203 'statement " Call Absolute ".
CALL Absolute(100) 'Call machine code.
B = PEEK(&HAAA) 'Get values for: Buttons
H = PEEK(&HBBB) + PEEK(&HBBC) * 256 'Horizontal position ( 2 bytes )
V = PEEK(&HCCC) + PEEK(&HCCD) * 256 'Vertical position ( 2 bytes )
END SUB 'End of sub-program.


Attachment:QBMOUSE.BAS (4463 bytes | downloaded 459 times)

Viewing all articles
Browse latest Browse all 25

Trending Articles