Key == someVariable does not work

I’d like to use a variable (int) with the key function, but it doesn’t work with or without single quotes. What can I do?

if(key == someVariable){

}

Thank you!

1 Like

because key is a character not a number,
better use
https://processing.org/reference/keyCode.html

int li = 76;
char lc = 'l';

void setup() {}
void draw() {}
void keyPressed() {
  println("key "+key+" keyCode "+keyCode);
  if ( key == 'l' )     println("see l");
  if ( key == lc  )     println("again l");
  if ( keyCode == li )   println("also see l");
}

for some keys that is not consistent over all OS’s

pls also test how to use?

if ((int)key == lk )   println("can use number (int)'l' also");
1 Like