Page 1 of 1

Clickable Area

Posted: Sat Jul 23, 2016 10:53 pm
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

Re: Clickable Area

Posted: Sun Jul 24, 2016 2:20 pm
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