Page 1 of 1

INPUT not preventing mouse clicks

Posted: Mon Jan 17, 2011 1:42 pm
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....

Posted: Mon Jan 17, 2011 1:47 pm
by Zylox
also: I am using QB64

Posted: Mon Jan 17, 2011 2:41 pm
by burger2227
Post some of your code.

Ted

Posted: Mon Jan 17, 2011 3:24 pm
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.

Posted: Mon Jan 17, 2011 10:21 pm
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

Posted: Mon Jan 17, 2011 11:09 pm
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!