# Button automatically clicked once at the beginning of the program

**URL:** https://discourse.processing.org/t/button-automatically-clicked-once-at-the-beginning-of-the-program/4995
**Category:** Libraries
**Created:** [October 29, 2018, 4:10pm UTC](https://discourse.processing.org/t/button-automatically-clicked-once-at-the-beginning-of-the-program/4995 "2018-10-29T16:10:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AllenLiu574](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@AllenLiu574](https://discourse.processing.org/u/AllenLiu574)
#### Post date: [October 29, 2018, 4:10pm UTC](https://discourse.processing.org/t/button-automatically-clicked-once-at-the-beginning-of-the-program/4995/1 "2018-10-29T16:10:27Z")

</div>

The following is part of the testing code I’m working on:  
I was trying to implement the button, and when it is clicked, it will print out the message “Button pressed”. I ran the program by clicking the run button on the top left corner of the Processing IDE. However, the console showed me the “Button clicked” message soon after the program begins, even when I did not click on the button I created. Does anyone know what had happened? Thanks to whoever my help  
import processing.serial._;  
import [java.io](http://java.io)._;  
import java.util._;  
import controlP5._;

ControlP5 cp5;  
Button mybutton;

void setup() {  
clear();  
size(480, 320);  
noStroke();  
cp5 = new ControlP5(this);

mybutton = cp5.addButton(“Press”)  
.setValue(0)  
.setPosition(16, 20)  
.setSize(168, 40)  
.setLabel(“Select CSV file”)  
.activateBy(ControlP5.RELEASE);  
;  
}

void draw() {  
background(128);  
}

public void Press() {  
println(“Button pressed”);

}

---

<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: [October 29, 2018, 5:47pm UTC](https://discourse.processing.org/t/button-automatically-clicked-once-at-the-beginning-of-the-program/4995/2 "2018-10-29T17:47:59Z")

</div>

that i see already,

> [@ControlP5 button event](https://discourse.processing.org/t/controlp5-button-event/4420/):
>
> Dear all, I wrote the following code: // --8\<-------8\<-------8\<-------8\<-------8\<-------8\<-------8\<-------8\<-------8\<----- // ``` ControlP5 cp5; final static String BUTTON\_START="buttonStart"; void initForm() { cp5 = new ControlP5(this); // cp5.setVisible(true); PImage[] imgs = {loadImage(PATH+PATH\_BUTTON+BUTTON\_START+RELEASED+".png"), loadImage(PATH+PATH\_BUTTON+BUTTON\_START+OVER+".png"), loadImage(PATH+PATH\_BUTTON+BUTTON\_START+PRESSED+".png")}; cp5.addButton("sta…

sorry, no idea how to avoid it.

---

<div class="post-metadata">

### Author: ![DongKingKong0](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dongkingkong0/32/960_2.png) [@DongKingKong0](https://discourse.processing.org/u/DongKingKong0)
#### Post date: [October 29, 2018, 5:54pm UTC](https://discourse.processing.org/t/button-automatically-clicked-once-at-the-beginning-of-the-program/4995/3 "2018-10-29T17:54:36Z")

</div>

This seems to be part of the cp5 library.  
Probably the easiest solution, since the event gets triggered immediately:

```auto
void press() {
  if (frameCount > 0) {
    // Do some stuff here.
  }
}

```

---

<div class="post-metadata">

### Author: ![FerrariLuigi](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@FerrariLuigi](https://discourse.processing.org/u/FerrariLuigi)
#### Post date: [October 30, 2018, 6:55pm UTC](https://discourse.processing.org/t/button-automatically-clicked-once-at-the-beginning-of-the-program/4995/4 "2018-10-30T18:55:04Z")

</div>

Ok. Thank you.  
🤩🤩
