With this code, how do i do this: the amount of time the mouse clicks without the user pressing the button constantly.
Author |
Message |
turing1094
|
Posted: Mon Jun 14, 2010 10:47 am Post subject: With this code, how do i do this: the amount of time the mouse clicks without the user pressing the button constantly. |
|
|
What is it you are trying to achieve?
I need to make the user click on the blue circle and evertime they do that it records it, so it gives the results after a certain period of time, however you can just press and hold the button, how do i change this.
What is the problem you are having?
read above
Describe what you have tried to solve this problem
cant solve it
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
setscreen ("graphics:vga")
var count : int:= 0
var x, y : int
var button : int := 0
var timepassed : boolean := false
var timepassed1 : int := 0
Draw.FillOval (300, 200, 50, 50, blue)
loop
Mouse.Where (x, y, button )
if button = 1
then
count := count + 1
end if
timepassed1 := timepassed1 + 1
delay(1)
if timepassed1 > 1000
then
timepassed := true
end if
exit when timepassed = true
end loop
put "Your score is ", count
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Mon Jun 14, 2010 11:09 am Post subject: RE:With this code, how do i do this: the amount of time the mouse clicks without the user pressing the button constantly |
|
|
Turing: | View.Set ("Graphics,Offscreenonly,Nobuttonbar")
var x : int := 0
var mx, my, mb : int
var reset, clicked : boolean := false
loop
%%%%%%%%%%%%%%%%%%
Mouse.Where (mx, my, mb )
%if mouse is not pressed, and reset is true then reset = false
if mb = 0 and reset = true then
reset := false
end if
%if the mouse is pressed and reset is false then clicked = true and reset = true
if mb ~ = 0 and reset = false then
clicked := true
reset := true
end if
%%%%%%%%%%%%%%%%%%
%when the mouse is clicked, do this ->
if clicked = true then
x + = 1
end if
put x
View.Update
cls
%sets clicked so that it is only true for one loop after clicked.
clicked := false
end loop |
|
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Jun 14, 2010 11:14 am Post subject: RE:With this code, how do i do this: the amount of time the mouse clicks without the user pressing the button constantly |
|
|
The detail to copthesaint's post is that you record the mouse state over 2 instances in time. 2 binary choices give you 4 possible mouse states:
-- clicked down
-- held down
-- released
-- held released |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
chrisbrown
![](http://compsci.ca/v3/uploads/user_avatars/18814724584bcbb8192aae8.png)
|
Posted: Mon Jun 14, 2010 11:33 am Post subject: Re: RE:With this code, how do i do this: the amount of time the mouse clicks without the user pressing the button consta |
|
|
Mouse.ButtonMoved and Mouse.ButtonWait are higher-level alternatives that take care of the details for you, if you prefer. |
|
|
|
|
![](images/spacer.gif) |
Cezna
![](http://compsci.ca/v3/uploads/user_avatars/9406831824c097251d4bb4.gif)
|
Posted: Tue Jun 15, 2010 3:08 pm Post subject: RE:With this code, how do i do this: the amount of time the mouse clicks without the user pressing the button constantly |
|
|
This is the method I normally use:
Turing: |
if button = 1 then
if not clicked then
% your code in here%
end if
clicked := true
else
clicked := false
end if
|
|
|
|
|
|
![](images/spacer.gif) |
|
|