keyPressed() does not work when P3D is used

Hi everyone,

The piece of code below works if P3D is removed from the size() tag. Why does this happen?

void setup() {
    size(1000, 650, P3D);

void draw(){

void keyPressed() {
  final int k = keyCode;
  if (k == 'a'||k == 'A') {

I need to use P3D with the code I am working with...



  • It works for me in Processing 3.0 here.
    As a side note, keyCode is never lowercase. No need to check for 'a' there. :-\"
    Perhaps it's worth it to check out the issue on GitHub too:

  • Processing 3.0 doesn't seem to work for me...I keep on getting

    "GLException: Method "glClearDepthf" not available"

    So I am still using Processing 2.

    I went on the websites you gave me and I tried this piece of code:

    import java.awt.event.KeyEvent;
    void setup() {
      size(100, 100, P3D);
    void draw() { }
    void keyPressed() {
      switch (keyCode) {
        case KeyEvent.VK_F1: println("F1:" + keyCode); break;
        case KeyEvent.VK_F2: println("F2:"+ keyCode); break;
        case KeyEvent.VK_F3: println("F3:"+ keyCode); break;
        case KeyEvent.VK_F4: println("F4:"+ keyCode); break;

    Again, with the P3D and P2D it does not work. Without them it does work.

    Am I missing something?

  • edited December 2015 Answer ✓

    I didn't imply for you to change your Processing version.
    Since it's the current version, I need to assume it is so when some1 asks a question here.
    Actually you shoulda said your own version right off the bat!
    I've just tested your 1st example in P 2.2.1 here and it's detecting the A key too!

  • True, sorry about that.

    I tried the first code again (removed the lowercase) but still when there is P3D it doesn't work and when I remove it, it works perfectly.

    I am finding this strange...

    I am persisting because in the other piece of code that I am working on I definitely need to use P3D.

  • I just realised that I was using the beta version of Processing 2...thank you

Sign In or Register to comment.