INPUT not preventing mouse clicks
INPUT not preventing mouse clicks
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....
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Post some of your code.
Ted
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
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
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.
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.
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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.
_MOUSEINPUT never misses an event! You MUST read it before you can get any readings from the other mouse functions.
Ted
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
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
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
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!
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!