Non-held issue KeyPressed() and KeyReleased()

Hello! I've become quite frustrated with the way the key input is handled. As I was attempting to make a 3d program with movement, and it works save for 1 major bug. The movement gets locked up, due to processing interpreting the key as not being pressed. After extensive testing I've narrowed it down, first I found out it only occurred if you pressed your mouse first, it would be held for a moment, then after that moment it would never be registered again. However, I also noticed this only is an issue in the 3d renders, when you use OPENGL in the size function, or P3D in the size function it will cause this error. In standard 2d programs this error is not present.

Here are 2 examples, Press W, it will tell you, yes the W key is pressed. Then click with your mouse, letting go of the W key. Press the W key again, hold it. You will notice the program using P3D changes to false, where the one not using P3D does not.

boolean keyDown[]= new boolean[256000];
void setup(){size(800,600);}
void draw(){
  background(0);
  fill(255,0,0);
  String tempStr="";
  for(int i=0;i<256000;i++){if(keyDown[i]){tempStr+=" "+char(i)+"["+i+"]";}}
  text(tempStr,width/2,height/2);
  text("Is the W key pressed? "+keyDown[char('W')],width/2,height/4);
  fill(0);
}
void keyPressed(){keyDown[keyCode]=true;}
void keyReleased(){keyDown[keyCode]=false;}

With P3D:

boolean keyDown[]= new boolean[256000];
void setup(){size(800,600,P3D);}
void draw(){
  background(0);
  fill(255,0,0);
  String tempStr="";
  for(int i=0;i<256000;i++){if(keyDown[i]){tempStr+=" "+char(i)+"["+i+"]";}}
  text(tempStr,width/2,height/2);
  text("Is the W key pressed? "+keyDown[char('W')],width/2,height/4);
  fill(0);
}
void keyPressed(){keyDown[keyCode]=true;}
void keyReleased(){keyDown[keyCode]=false;}

I'm working on a final project for highschool, and as far as any reference or books say, or my teacher for that matter say. The code I am writing is perfectly fine, my guess is that it is registering the windows typed key event in the 3d program, rather than the native key event. If anyone knows absolutely anything about solving this problem, even if it is not processing specific, but uses an external library or native java, please tell me as this is an important problem I can not seem to place.

EDIT: It should also be noted, using standard key checks manually, using hashmaps, passing the entire pressed function to another class, do not work.

Tagged:

Comments

  • _vk_vk
    edited November 2013

    Running on osx 10.8.5 - P5 2.0.1 it didn't happen. Worked fine both renders...

  • I run this issue when using windows XP, windows vista, windows 7, and windows 8. I believe I wrote it could be processing's use of the windows input, as there is a windows input for typing, and a windows input for direct use. The one I think they're using is for typing, where if you hold a key, it is pressed and then it pauses, and constantly presses the key (much like when you hold down a in a word editor). The second one is for games (which is what I am trying to use), where when the key is pressed, it is constantly being told the signal of a key pressed.

    Did you do the steps I suggested in order? Step 1: Hold W to see that it works. Step 2: Let go of W. Step 3: Click with the mouse a few times. Step 4: Hold W again. Step 5: Observe how it will no longer register the W as being pressed.

    I assume you did, nevertheless is there any work around where I can use a more direct input, as with 5 computer I've tested this bug is consistent. Thanks.

  • yep, every step.

  • Well the issue persists with me for every operating system I use. It would help if you could recreate this issue, do you have a windows pc?

  • edited November 2013

    Another test that produces this bug is hitting a random set of keys, then holding them in the P3D and you'll notice one stops showing up.

Sign In or Register to comment.