INPUT not preventing mouse clicks

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
Zylox
Newbie
Posts: 4
Joined: Mon Jan 17, 2011 1:38 pm

INPUT not preventing mouse clicks

Post by Zylox »

In a program I am working on, I am having trouble with input not preventing mouse clicks. It seems to be remembering the clicks no matter what I do, which leads to improper values being displayed if clicks are made in certain spots during the input. I could really use some help....
Zylox
Newbie
Posts: 4
Joined: Mon Jan 17, 2011 1:38 pm

Post by Zylox »

also: I am using QB64
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Post some of your code.

Ted
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
Zylox
Newbie
Posts: 4
Joined: Mon Jan 17, 2011 1:38 pm

Post by Zylox »

Don't know what sections you want so ill just take a stab at it.


this is the main click detection section. I wrote it to go to a sub that detects the upclick instead of the downclick.

DO

annoyance = _MOUSEINPUT

IF _MOUSEBUTTON(1) = -1 THEN
GOSUB Clickcheck
END IF

IF INKEY$ = "m" THEN
END
END IF

LOOP


It goes to here to detect the up click, then acts accordingly based on the mouse postion at the time of the upclick (there is a long set of if thens after it for several buttons)


Clickcheck:
DO
annoyance = _MOUSEINPUT
LOOP UNTIL _MOUSEBUTTON(1) <> -1


Now the problem seems to be occuring here (different part of program)

INPUT " ", decimalval~&&

if I click within a buttons parameters while inputing, it seems to remember the click and execute the buttons actions after the input, even though input is supposed to stop the program.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You only have to clear _MOUSEINPUT after the INPUT by running it in a loop. I added a count just so that you can see how many times it looped before it cleared.

If you only click the mouse and don't move it after pressing the "i" key, the number of loops is twice the number of clicks as each click has a press and release event. If you move the mouse too, there will be more loops.

Comment out the GOSUB line to see how the click * are printed after the INPUT like you said. You can remove the count lines in the GOSUB.

Code: Select all

DO
  K$ = LCASE$(INKEY$)
  DO WHILE _MOUSEINPUT
    IF _MOUSEBUTTON(1) = -1 THEN PRINT "*"
  LOOP
  IF K$ = "m" THEN END
  IF K$ = "i" THEN
    INPUT "Click the mouse and enter something: ", entry$
    GOSUB Clickcheck
  END IF
LOOP

END

Clickcheck:
count = 0
DO WHILE _MOUSEINPUT
  count = count + 1
LOOP
PRINT count
RETURN
_MOUSEINPUT never misses an event! You MUST read it before you can get any readings from the other mouse functions.

Ted
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
Zylox
Newbie
Posts: 4
Joined: Mon Jan 17, 2011 1:38 pm

Post by Zylox »

I actually figured out the problem after I read your reply, and your way fixed it too. The problem was that it detected that there was a click during the input so it immediately went to the clickcheck sub, where it detected that the click had passed so it changed the values of the buttons based on the x and y values of the mouse. The problem was that i had not actually written anything into the sub where it would exit if a button wasnt actually being pressed at the time of entry (because it hadn't crossed my mind), so I just wrote in an exit procedure if that was the case.
I had actually tried the method you had suggested, but in the wrong place. This time I got it right and it cleared the input properly.
Thank you for your suggestions!
Post Reply