arduino processing, light up rect

hello,

I am stuck trying to figure out how to get the rect to light up when one of the keyboard buttons is pressed but they all seem light up when a key is pressed, i have coded this in processing 2.2, please excuse my bad coding as i am not familiar with java.

thanks

import processing.serial.*;

Serial myPort;  
int val;        

void setup() 
{
  size(350, 330);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}






void draw() {
  if (keyPressed) {
    if (key == 'w' || key == 'W') {
      fill(0);
      myPort.write('W');  
    }
  } else {
    fill(255);
    
  stop();
  }
  rect(150, 90, 50, 50);


  if (keyPressed) {
    if (key == 'a' || key == 'A') {
      fill(0);
      myPort.write('A'); 
    }
  } else {
    fill(255);
     stop();
  }
  rect(80, 160, 50, 50);
  
  if (keyPressed) {
    if (key == 's' || key == 'S') {
      fill(0);
      myPort.write('S'); 
    }
  } else {
    fill(255);
    stop();
  }
  rect(150, 160, 50, 50);
  
  if (keyPressed) {
    if (key == 'd' || key == 'D') {
      fill(0);
      myPort.write('D'); 
    }
  } else {
    fill(255);
    stop();
  }
  rect(220, 160, 50, 50);
}

void stop(){
 myPort.write('L');
 return;
}

The language used in the Arduino IDE is not Java, but C++ at the heart, although most Arduino program sketches are written in C. Try reading some of the examples that are distributed with the compiler (e.g., menu sequence File --> Examples) combined with some of the online C tutorials. A little time with those should help get you started.

econjack: The language used in the Arduino IDE is not Java, but C++ at the heart, although most Arduino program sketches are written in C. Try reading some of the examples that are distributed with the compiler (e.g., menu sequence File --> Examples) combined with some of the online C tutorials. A little time with those should help get you started.

i am not using the arduino IDE. im using processing 2.2 i believe it is java but i could be wrong, thats the program code to send serial data to the arduino to tell it what to do.