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
Aureal
Newbie
Posts: 3
Joined: Sat Jul 23, 2016 10:46 pm

Clickable Area

Post by Aureal »

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
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: Clickable Area

Post by burger2227 »

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

DO
    _LIMIT 1000 'QB64 code
    DO WHILE _MOUSEINPUT 'QB64 code or use another mouse routine
    LOOP
    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 : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply