QWERTY keys do not work

Hi guys.
I’m so sorry, but I’m a newbie in jME and in gamedev as well. And unfortunately I’ve no any tutor by this topic to ask him.
So now I learn basic tutorials from https://wiki.jmonkeyengine.org/jme3/beginner
Everything went well but I faced a problem. When I researched HelloCollision example, I found out that QWERTY keys did not work, i.e. they did not respond to pressing of my keyboard. But! Space key did! (WASD - for moving, like in example).
OK. I checked my code twice and after that copied and pasted it from example. Keys had no response, but Space key had. After that I tried to add System.out.println into that part:
public void onAction(String binding, boolean isPressed, float tpf) {
switch (binding) {
case “Jump”:
System.out.println(“Jump”);
if (isPressed) { player.jump(new Vector3f(0,20f,0));}
break;
case “Left”:
System.out.println(“Left”);
// left = isPressed;
break;
case “Right”:
System.out.println(“Right”);
// right= isPressed;
break;
case “Up”:
System.out.println(“Up”);
// up = isPressed;
break;
case “Down”:
System.out.println(“Down”);
// down = isPressed;
break;
default:
break;
}
}

to send information to console. And I saw only “Jump” messages.

Well, I changed key-mapping and used numerical keys for moving character (2 - forward, 1 - left, 3 - right, 4 - back) - and they worked.

System I use is:

  • jME: jMonkeyEngine SDK v3.2.4-stable-sdk1
  • Java: 1.8.0_212; OpenJDK 64-Bit Server VM 25.212-b04
  • OS: CentOS Linux 8

My question is - what is a problem? Is something wrong with jME, or system, or any drivers, or java, or may be my hands? But I finally stupidly copied code from example and saw the same behavior. And what can I read, recheck, try or fix.

I hope to any advice to continue studying jME. Thank you.

i dont see addListener / addMapping methods here where you declare keys binded.

here example declare keys to work with listenter in example you talk about:

  private void setUpKeys() {
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(this, "Left");
    inputManager.addListener(this, "Right");
    inputManager.addListener(this, "Up");
    inputManager.addListener(this, "Down");
    inputManager.addListener(this, "Jump");
  }

QWERTY will not work, since there is no Q or E or R or T o Y defined in this example.

Yep! Sure! you are right. Of cause I have this method and I call it in my main. I just did not put whole code here. You can find it on github.
I just made a few changes unlike original example: changed ‘if’ to ‘switch’ clause and strings to defined constants. Any ideas?

like i said, you need define Q or E or R or T o Y for:

image

i hope you see there is only A D W S and Space… thats why QWERTY dont work.

  1. add new Key Triggers for QWERTY
  2. add addListener for this keys
  3. in your switch, add conditions for Q W E R T Y keys.

I see, in “QWERTY” I meant whole letter keybord (sorry I don’t know English equivalent). Of cause I mapped and tried WASD keys, I tried to change them to another and found out that all letters do not work. But when I changed mapping to numerical keys (1, 2, 3, 4) they worked.
e.g

inputManager.addMapping(“Left”, new KeyTrigger(KeyInput.KEY_1));

So I have a problem that letter keys do not work, but numbers and Space do.

ok, now i understand fully the problem.

But i cant find why KEY_ A-Z would not work.

Could you try:

https://wiki.jmonkeyengine.org/jme3/beginner/hello_input_system.html

example?

Also if you use SDK, you can Create JME Tests project there and check if everything work fine in Tests and compare code.

Also do you use LWJGL 2 or 3? jme-lwjgl or jme-lwjgl3 package. or maybe jogl? need more information here also. (since on your Github page, i dont see any build properties)

Well, about lwjgl lib.
Снимок экрана от 2020-05-30 20-00-54
I have the following. Not sure what exactly versions, because I can see jme3-lwjgl-3.2.4-stable.jar and lwjgl-2.9.3.jar. These libs were loaded by default.

About test projects. Thank you for advice, I tried them. E.g. TestCameraNode uses move controls on arrow and WASD keys both. And… Arrow keys works well, but WASD does not :slight_smile:
And with HelloInput example the same situation.

interesting, if even SDK Test dont work for A-Z keys…

Worth to put ticket on Github page, since JME Tests should always work.

im not sure if this one is related:

Anyway you could try use LWJGL2 and see.
i dont rememebr how to switch using Ant and SDK, but using Gradle like below link, you could just use jme-lwjgl instead jme-lwjgl3

even so, it would require some tests from your side, asscessing input parsing on lower level and check what happends there.

Generally looks like LWJGL issue, not your code, since JME Tests also have same issue.

Edit: I totally misread parts of this thread and found the issue you were primarily concerned about: keys not responding! Added the appropriate stuff at the top and the older stuff at the bottom in case it helps you sometime later.
In your code these are the parts I believe are your trouble spots:

private static final String LEFT = "Left";
private static final String RIGHT = "Right";
private static final String UP = "Up";
private static final String DOWN = "Down";
private static final String JUMP = "Jump";

//Elsewhere in the code
private void setUpKeys() {
  inputManager.addMapping(LEFT, new KeyTrigger(KeyInput.KEY_A));
  inputManager.addMapping(RIGHT, new KeyTrigger(KeyInput.KEY_D));
  inputManager.addMapping(UP, new KeyTrigger(KeyInput.KEY_W));
  inputManager.addMapping(DOWN, new KeyTrigger(KeyInput.KEY_S));
  inputManager.addMapping(JUMP, new KeyTrigger(KeyInput.KEY_SPACE));
  inputManager.addListener(this, LEFT);
  inputManager.addListener(this, RIGHT);
  inputManager.addListener(this, UP);
  inputManager.addListener(this, DOWN);
  inputManager.addListener(this, JUMP);
}

@Override
public void onAction(String binding, boolean isPressed, float tpf) {
  switch (binding) {
    case JUMP:
      System.out.println(JUMP);
      if (isPressed) { player.jump(new Vector3f(0,20f,0));}
      break;
    case LEFT:
      System.out.println(LEFT);
      left = isPressed;
      break;
    case RIGHT:
      System.out.println(RIGHT);
      right= isPressed;
      break;
    case UP:
      System.out.println(UP);
      up = isPressed;
      break;
   case DOWN:
      System.out.println(DOWN);
      down = isPressed;
      break;
   default:
      break;
    }
}

I’m not sure why it’s not working like that but I would try the following for your case:

private void setUpKeys() {
  inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
  inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
  inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
  inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
  inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));
  inputManager.addListener(this, "Left");
  inputManager.addListener(this, "Right");
  inputManager.addListener(this, "Up");
  inputManager.addListener(this, "Down");
  inputManager.addListener(this, "Jump");
}

@Override
public void onAction(String binding, boolean isPressed, float tpf) {
  switch (binding) {
    case "Jump":
      System.out.println(JUMP);
      if (isPressed) { player.jump(new Vector3f(0,20f,0));}
      break;
    case "Left":
      System.out.println(LEFT);
      left = isPressed;
      break;
    case "Right":
      System.out.println(RIGHT);
      right= isPressed;
      break;
    case "Up":
      System.out.println(UP);
      up = isPressed;
      break;
   case "Down":
      System.out.println(DOWN);
      down = isPressed;
      break;
   default:
      break;
    }
}

Using that code with yours seemed to get them to respond for me so try that for the time being. Just eliminate the private static finals you had for each string and just list the strings as above. Hope it helps!

Did you try it with the constants? I bet it works for you with the constants, too, since Java will make the exact same byte code for both versions.

Your other changes have nothing to do with his issue, also… as the original code is fine (other than setting the camera location at a time that will cause jitter)… the only difference is that your version will walk 2.0/0.6 times faster.

I tried with the constants but it did not perform as one would expect. When using the code as is before modifying it, the Up and Down controls did not respond/operate but the Left and Right did. I fiddled and posted what I assumed was shorter and more plausible as that’s what I came to to get it working for their case. It stumped me for sure.

And yea I realized that after I posted the comment and shortly after debated whether it was best to delete the unneeded bit and just leave the edited info that did relate to the core issue since no one had replied to it right then.

OP wasn’t even seeing the print messages… so anything related to movement after keys were detected is a different issue.

If you see the print messages with OP’s code then you are not experiencing his issue.

Hmmm… Today I tried to add

System.out.println("Binding is: " + binding);

in the beginning of “onAction” method (before “switch” operator) and found that when I press WASD buttons “onAction” is not executed at all. And when I use numerical keys mapping (and Space) it works.

By the way, how to correctly put code here? Are any tags? Something like ‘code’?

Three back ticks. It’s markdown.

1 Like

https://imgur.com/Ase9ixI.png

Oops! I was very attentive. :slight_smile:
Thank you.

Well, I think that for now I can continue basic tutorials analysis and reading basic descriptions. Of cause that issue is nasty, but it can’t affect studying process. I can proceed to use for my training code numerical keys and return to this issue later.

So guys, I made an experiment yesterday. I changed CentOS to Ubuntu and installed the same SDK v3.2.4 with the same set of libs. To ensure that I did not change anything in code, I copied my old project as is. And all keys works fine now. So I think that perhaps there were some issues with compatibility in CentOS 8 (I’m not sure, but I think so). Anyway it works fine for now and I can proceed to work in Ubuntu.
Thank you all for your help. I think the issue is solved for me now.

one of used platform here is newest Centos 8, and it works here, so i dont think its it.

Do you use 3.2.4 jME as well?

i dont remember now, Centos 8 is new, so maybe i were using 3.3+ already there when it was out.