For the longest time, I had wanted to find a way to use the mouse in my own QBasic programs. While I eventually found several fine examples of code on-line that did in fact interface with the mouse, they all seemed very complicated to me, with multiple sub-routines, functions and procedure calls. So, I decided to "boil it all down" to the simplest, bare-minimum method, and to my knowledge, what I came up with is still the quickest, easiest way to incorporate mouse functions into a QBasic program!
One might think of my code as a kind of "black box" or "plug-in" of sorts; you simply copy my "Mouse" sub-routine into your program, and it immediately provides rudimentary mouse support! Interfacing with the mouse is then accomplished by way of three simple functions; "Mouse 1" shows the mouse cursor, "Mouse 2" hides it again, and "Mouse 3" reads the mouse's current button status as well as it's location. This information is communicated to the user's program through 3 global variables; "B" represents the mouse buttons, "H" contains it's horizontal co-ordinates, and "V" returns it's vertical co-ordinates. For a 2-button mouse, the variable "B" will return the following values:
VALUE: BUTTON(S) PRESSED:
0 None
1 Left
2 Right
3 Both
The following is the actual mouse code segment which provides mouse support:
''''''''''''''''''''''''''''''''''''''''''''''''''' 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.
The following statements should be the first two commands in any program which uses this code:
DEFINT A-Z
DECLARE SUB Mouse (Funk) ' Declare Mouse sub-program.
Along with this instructable, I have included a sample program ( "QBMOUSE.BAS" ) as well as a "template" of sorts ( "MOUSE.SUB" ), which contains the Mouse sub-routine, and a blank main program, where you would enter your own code. Should you have any questions, concerns or just gripes regarding this code, please feel free to contact me at; flurng@gmail.com. I welcome any feedback, and I hope you enjoy creating exciting new mouse-enabled QBasic programs with the help of this sub-routine.
When you're ready to begin, read on to the first step, and above all...... Have Fun!!!
Remove these ads by
Signing UpStep 1Download Files
When you're finished doing this, move on to Step 2........
| « Previous Step | Download PDFView All Steps | Next Step » |
1
comment
|
Add Comment
|
![]() |
Add Comment
|









































