Problems with true false

Hi, I have some troubles. I want to make a boolean true when I press a bottom and then stay true but it always changes back to false

depends on the use, a toggle with one key would be

boolean myBoolean=false;

void setup(){}
void draw(){}
void keyPressed(){
 if ( key == 't' ) {
   myBoolean = ! myBoolean;
   println("see key t "+myBoolean); 
 }
}

or use two keys for set true resp. false.

is it possible to make it in draw?

idea is to change it by keyboard? then do like i show you.

but use it in draw… that is the idea.

but a very common use would be

boolean myBoolean=false;

void setup(){}
void draw(){
//...
  if ( myBoolean ) {
    // do something on keypress but only one time
    myBoolean=false;
  }
}
void keyPressed(){
 if ( key == 't' ) {
   myBoolean = true;
   println("see key t "+myBoolean); 
 }
}

Well I can’t figure out how to make it stay as true. What i wanted to make is i want to press a bottom once and then the boolean stays at true until i say otherwise

boolean myBoolean=false;

void setup(){}
void draw(){
//...
  if ( myBoolean ) {
    // do something on keypress 
  }
}
void keyPressed(){
 if ( key == 't' ) {
   myBoolean = true;
   println("see key t "+myBoolean); 
 }
}

Since you don’t show your code:

Using the variable keypressed as opposed to the function keypressed () can often cause that a key is registers multiple times.

So, when you use a toggle on the Boolean variable (using … = ! …) it will uncontrollably reach one of its two states - bad.

Chrisir