# Detect double click inside class

**URL:** <https://discourse.processing.org/t/detect-double-click-inside-class/15793>\
**Category:** Coding Questions\
**Created:** [November 25, 2019, 11:02am UTC](https://discourse.processing.org/t/detect-double-click-inside-class/15793 "2019-11-25T11:02:20Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 26, 2019, 6:02am UTC](https://discourse.processing.org/t/detect-double-click-inside-class/15793/9 "2019-11-26T06:02:57Z")

</div>

ok, thanks, but that was not the help for the event question.

and a own event handler for the class would be the long way,  
but just take a look how the PRO’s are doing it  
[Text input for choosing Colour](https://discourse.processing.org/t/text-input-for-choosing-colour/15772/2) .  
a ( reduced ) G4P example

but here we try in small steps:

* * *

lets start again from the functional side:

as a electrician i know the difference between a

- push button
- switch

but here in coding what we actually have?  
the button class acts like a switch,  
when click mouse LEFT, the switch goes from OFF to ON.  
( because it has a latching memory .sel )

if we write some code in main  
( continuously polling )  
bad style  
`if ( button[17].sel ) {}`  
better class code  
`if ( button[17].get_sel() ) {}`  
we can do what we need to do, and  
then a  
`button[17].reset();`  
so we not see the ( .sel == true ) again in the next loop.

in other words from main we converted the switch to a push button  
( might not even see the green fill color )  
that is also a correct event thinking.

* * *

but if we want / need the switch as a switch  
we want following 3 information:  
-1- event ( click ) OFF to ON  
-2- status ON or OFF  
-3- event ( click ) ON to OFF  
this we can do if we compare the .sel status while polling  
with a memory variable in main ( last\_sel = …sel;)  
easy but kind of ugly,

assuming that via draw and button display the codes are synchronized  
it might be enough to have 2 add event bits in the class.

- .rise
- .fall

what will be true only for one cycle.  
in case of asynchronous operation we must make them latching until read || reset.

* * *

in this case with .sel and .seld it is a little bit more complicated.

so…  
what you need ( on double click )

- push button ?
- switch ?

thinking.

---

_[View the full topic](https://discourse.processing.org/t/detect-double-click-inside-class/15793)._
