Clickable Area

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Posts: 3
Joined: Sat Jul 23, 2016 10:46 pm

Clickable Area

Post by Aureal » Sat Jul 23, 2016 10:53 pm

Hi, I'm somewhat new to QBasic, so I would like to know how to set a clickable area on the screen.
I'm currently using a Mouse Subroutine I found on the internet, When called (e.g. MOUSE 3) it returns H (X), V(Y), and the button presses(1 for left, 2 for right and 3 for both).

Anyways, I would want to set a clickable area like, for example (0,0)-(10,10). When the mouse is in that area and presses the left button, It'll do something, and when pressed within (11,11)-(21,21), It'll do something else.

Thanks in advance! :D

User avatar
Posts: 2409
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: Clickable Area

Post by burger2227 » Sun Jul 24, 2016 2:20 pm

Place a square box using LINE with BF and use the outer coordinates to find where the mouse is:

QB64 code:

Code: Select all

SCREEN 12 'must not use SCREEN 0
LINE (1, 1)-(100, 100), 12, BF

    _LIMIT 1000 'QB64 code
    DO WHILE _MOUSEINPUT 'QB64 code or use another mouse routine
    mx = __MOUSEX: my = _MOUSEY: LB = _MOUSEBUTTON(1) 'QB64 code
    IF mx >= 1 AND mx <= 100 THEN ' columns
        IF my > 1 AND my <= 100 THEN ' rows
            IF LB THEN
                LOCATE 10, 10: PRINT "Mouse clicked in box"
                SLEEP 1
                LOCATE 10, 10: PRINT SPACE$(30)
            END IF
        END IF
    END IF
LOOP UNTIL INKEY$ <> "" 'any key press exits
Edited. Try my QB Demonstrator below
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX :
Get my Q-Basics demonstrator: ...

Post Reply