Computer Science Canada Detecting a Double Click |
Author: | Prince Pwn [ Tue May 10, 2011 2:06 pm ] | ||
Post subject: | Detecting a Double Click | ||
What is it you are trying to achieve? Obtaining if a double click occurs What is the problem you are having? Cannot detect time since last click Describe what you have tried to solve this problem Creating a counter if button = 1 but continues counting as long as button is held. This is due to button always equalling 1 as long as button is held. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using 4.1 |
Author: | Tony [ Tue May 10, 2011 2:21 pm ] |
Post subject: | RE:Detecting a Double Click |
If you sample the mouse in two consecutive steps, you get a total of 4 different mouse states. E.g: [Down, Down] is just the button held down; [Down, Up] is the instance when the button was released up; etc. |
Author: | Prince Pwn [ Tue May 10, 2011 2:57 pm ] |
Post subject: | RE:Detecting a Double Click |
What do you mean by sampling it in two steps, like a mouse.where after a mouse.where? How does that work exactly. |
Author: | Tony [ Tue May 10, 2011 3:03 pm ] | ||
Post subject: | RE:Detecting a Double Click | ||
Mouse.Where will give you the state of the mouse at some point in time. If you plot the mouse's state over a period of time, a click might look something like
To detect the | edge, you would need to consider more than a single point. |
Author: | tyuo9980 [ Tue May 10, 2011 4:07 pm ] |
Post subject: | Re: Detecting a Double Click |
detect the time in between the clicks. if the delay is short enough then label it as a double click. say if you want to detect a double click up to 1 second. timelast := Time.Elapsed loop if clicked then timenow := Time.Elapsed end if if timenow - timelast < 1000 then timelast := timenow <- to reset time counter *your button thing here* end if end loop |
Author: | Raknarg [ Tue May 10, 2011 6:11 pm ] | ||
Post subject: | Re: Detecting a Double Click | ||
Why don't you try using a counter? If it was me, I would have something like this:
|
Author: | Zren [ Tue May 10, 2011 6:37 pm ] | ||
Post subject: | Re: Detecting a Double Click | ||
Raknarg @ Tue May 10, 2011 6:11 pm wrote: Why don't you try using a counter?
If it was me, I would have something like this:
Why count to infinity when you don't need to? That counter will add to the total CPU use. It's also in effect when you're not even clicking. All you really need is a timestamp. It'll also cause integer overflow if left long enough and a miraculously timed return could missfire. |
Author: | Prince Pwn [ Wed May 11, 2011 2:28 pm ] | ||
Post subject: | RE:Detecting a Double Click | ||
The issue I'm encountering is when you click the mouse once, ie : if mousebutton = 1, that holds true even if you press mousebutton like half a second. So any code you put in there gets executed many times. And I don't want a delay to slow the entire program. edit: messy but i think i got it:
problem is if you hold it down too long it bombs out. |
Author: | Tony [ Wed May 11, 2011 2:48 pm ] |
Post subject: | Re: RE:Detecting a Double Click |
Prince Pwn @ Wed May 11, 2011 2:28 pm wrote: problem is if you hold it down too long it bombs out.
That's why mouse events are typically fired at MouseDown or MouseUp, as those are transitional states and cannot be held in place (as discussed above). |
Author: | Zren [ Thu May 12, 2011 6:07 am ] | ||
Post subject: | RE:Detecting a Double Click | ||
Here's an example with keyboard input, extending it to mouse input shouldn't be too hard.
|