We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › mousePressed more than once
Page Index Toggle Pages: 1
mousePressed more than once? (Read 806 times)
mousePressed more than once?
Nov 29th, 2009, 2:39am
 
Hi is there a way Processing can recognise if the mouse is pressed more than once? Sorry if I haven't looked hard enough for the answer to this question.

I wanted to increase a value by clicking to increase that value more with each click, using some mousePressed type code? I'm a newbie sorry.

Thanks.
Re: mousePressed more than once?
Reply #1 - Nov 29th, 2009, 7:33am
 
You just have to create a variable and increase it each time the mouse is pressed:

Code:
int counter;

void setup() {
 size(100,100);
}

void draw() {

 
}

void mousePressed() {
 counter++;
 println(counter);
}



'counter++;' is a shortcut for:

counter = counter + 1;

Note that there are different ways of handling mouse press (see the Reference) and which one you choose depends on what you want to achieve.  The function outside of draw (as used above) would be used generally if you want something to happen only once each time the button is pressed.  The mousePressed variable might be used in draw to make something happen for as long as the button is pressed.
Page Index Toggle Pages: 1