Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to enable mouse in QBasic

GatisGatis Posts: 6
I'd like to make a program with mouse controls but can't get any information how to do that. For me everything is clear about keyboard scancodes, but where to get information about using mouse in Qbasic.
Please help me to find a solution.



  • marinsoftmarinsoft Posts: 10
    Hello, I wrote a mouse routines library for Quick Basic. It works both for interpreted programs and compiled programs and it is very easy to use. You can download the library from this site at
    It include explanation and simple examples.
    Good look and remember you can make any question. Don't forguet to rate the library.


    : I'd like to make a program with mouse controls but can't get any information how to do that. For me everything is clear about keyboard scancodes, but where to get information about using mouse in Qbasic.
    : Please help me to find a solution.
    : Thanks.

  • flurngflurng Posts: 10
    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 ( ), '
    ' 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.
  • RoseSurajRoseSuraj Posts: 5
    Hi Daryl

    I am new high school boy here and begineer in Q Basic too. In the code you have send, I hope that "Absolute(100)" is only called but not declared. Also there is no any sub- procedures of "Absolute(100)"

    Also please help me in converting ".bas" files into ".exe".....................
    I am so hopeful from you........
  • flurngflurng Posts: 10
    Greetings, Suraj!

    Thanks for your interest in my code. To answer your questions; no, the statement "Call Absolute" is not declared, nor will you find a sub-procedure relating to it. This is because the statement is built-in to QBasic, much like the "SQR()" function, which returns the square root of any value in the parentheses, or "ABS()", which returns a pure numeric value, without regard to + or - signs.

    The "Call Absolute(100)" statement tells QBasic to execute a special routine written directly in binary machine language, and the number in parentheses (in this case, 100) tells QBasic the memory location where that machine language code begins.

    Notice the series of "Poke" statements immediately proceding the Call Absolute statement, beginning with "Poke 100,184". These statements tell QBasic to "Poke" (write) specific binary values directly into memory, at a specific address. Thus, the first Poke statement tells QBasic; "write into memory address 100, the value 184". (QBasic automatically converts the decimal value 184 into binary and then writes that value into memory.)

    Now, if you'll notice, the next Poke statement specifies memory location 101, the next one 102, and so on. This is why we use Call Absolute with the value 100. However, had the first statement read "Poke 200,184", then we would have used "Call Absolute(200)".

    The remaining Poke statements write various binary values into memory, and these values correspond to specific machine language commands, which instruct QBasic how to interact with the mouse driver. Different commands could just as easily relate to some other device, such as a soundcard or CD-Rom drive.

    As for how QBasic knows where the machine code ends, notice the last Poke statement; "Poke 117,203". In this case, the value 203 represents the machine language "return" command, which sends QBasic back to the statement immediately following "Call Absolute(100)", where your program resumes as normal.

    As far as converting ".bas" files into ".exe" (executable) programs is concerned, you need a type of program known as a "compiler". QBasic, however, is an "interpreter" program, which converts Basic code statements into machine language one-by-one, line-by-line and then executes them immediately on-the-fly. Therefore, each time you wish to run your program, QBasic needs to re-interpret your code, which is why it cannot run on its own. In effect, QBasic is actually doing the hard work; your program is simply telling QBasic what to do.

    By contrast, a compiler converts basic code statements into machine language, but it does not execute them immediately. Instead, it writes those commands, in machine language form, into a separate file, which becomes your executable (.exe) program. Once this process is complete, your program can be run on its own, without the compiler's help.

    As it happens, the QBasic interpreter program was actually derived from a related program called "QUICKBasic". QUICKBasic is a true compiler, and actually sold as a professional development tool. Around the time that Microsoft released MS-Dos version 5.00, they wanted to get more people interested in programming, so they effectively "stripped-down" the QUICKBasic compiler into the QBasic interpreter program, and bundled it with MS-Dos, free of charge.

    Therefore, the easiest way to convert your code to .exe programs would be to compile them with QUICKBasic. Unfortunately, Microsoft no longer distributes QUICKBasic, but I have a copy of it somewhere, and If I can find the disc, I'll happily send you a copy. If not, you might try Googling it - there are still a few links to it out there. Another option would be to try FIRSTBasic. This is another Basic compiler program, created by a company known as POWERBasic. It is slightly less compatible with QBasic code than is QUICKBasic, meaning your code may need some minor alterations, however it can be downloaded directly from programmersheaven at the following link; , and with some practice, you'll find it just as easy to work with as QBasic!

    I hope this information was helpful, and I welcome any further questions you may have - it's always a pleasure to help out a fellow programmer! Take care for now, and above all, Have FUN programming!
    Daryl Dubbs

  • RoseSurajRoseSuraj Posts: 5
    Hi Daryl,

    I am indebted to you for your help to me. I heartly thanks you. And if you find the disk, please help me by sending its copy......

  • flurngflurng Posts: 10
    Hello again, Suraj!
    I'm afraid I still have not found my QuickBasic disc. However, I did find a .zip file online containing the most recent version of QuickBasic, namely version 4.5. I would attach a copy to this post, but this forum does not allow uploading executable files. You can, however, try downloading it yourself from the "downloads" page of, where I found it. I hope this helps. It's a real pleasure to lend a hand when I can, because I remember what it's like to be just starting out, wishing someone could do the same for me! And of course, as always, remember to Have FUN programming! So long for now - let me know if you have any further troubles!
  • flurngflurng Posts: 10
    This post has been deleted.
  • flurngflurng Posts: 10
    This post has been deleted.
  • flurngflurng Posts: 10
    Hello again, Suraj!
    I haven't heard from you in a while, so I thought I'd drop you a line & see how you're doing; were you able to find a copy of QuickBasic? Also, I was just wondering if my mouse code has been helpful to you. Please give me a shout if you get a chance, and certainly if you've any more questions I may be able to help with - always a pleasure to share knowledge with others! Take care for now, & whatever else you do with your programming, HAVE FUN!
  • sagar123sagar123 nepalPosts: 2

    Hey flurng!!
    I am an amateur programmer in qbasic. Can you please decribe sub mouse content..
    Cause I really need your help man.

Sign In or Register to comment.