libgdx icon indicating copy to clipboard operation
libgdx copied to clipboard

[Bug] Gdx.input.isKey(Just)Pressed(Keys.BACKSLASH), doesn't seem to work on Linux Mint 18 KDE Edition

Open physios opened this issue 8 years ago • 8 comments

Issue details

Gdx.input.isKeyJustPressed(Keys.BACKSLASH) and Gdx.input.isKeyPressed(Keys.BACKSLASH) wont work on Linux Mint 18 KDE Edition, on windows it works fine, but on Linux it doesn't give any output. KeyUp and KeyDown from InputProcessor won't respond to backslash although KeyTyped will respond appropriately, thus a workaround is to check when KeyTyped returns '\'.

I tested this with the same keyboard layout and using Linux Mint 18 KDE Edition and Windows 10

The backslash will work to open (for example) CSGO's console.

Reproduction steps/code

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class DasTesten extends ApplicationAdapter {
	SpriteBatch batch;
	Texture img;
	
	//When false, displays libgdx logo, when true it won't
	private boolean testen = false;
	
	@Override
	public void create () {
		batch = new SpriteBatch();
		img = new Texture("badlogic.jpg");
	}

	@Override
	public void render () {
		Gdx.gl.glClearColor(1, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		//Test #1, won't work on Linux (Tested on Linux Mint 18 KDE Edition)
		if(Gdx.input.isKeyJustPressed(Keys.BACKSLASH)){
			testen = !testen;
		}
		
		//Test #2, must work everywhere
		if(Gdx.input.isKeyJustPressed(Keys.A)){
			testen = !testen;
		}
		
		//The outcome
		if(!testen){
			batch.begin();
			batch.draw(img, 0, 0);
			batch.end();
		}
	}
	
	@Override
	public void dispose () {
		batch.dispose();
		img.dispose();
	}
}

Then try pressing backslash (I am using an PT-PT Keyboard layout so the backslash key is above tab)

Version of LibGDX and/or relevant dependencies

1.9.5

Stacktrace

N/A

Please select the affected platforms

  • [ ] Android
  • [ ] iOS (robovm)
  • [ ] iOS (MOE)
  • [ ] HTML/GWT
  • [ ] Windows
  • [x] Linux
  • [ ] MacOS

physios avatar Jan 12 '17 02:01 physios

Same code doesn't work on Ubuntu 16.01 LTS too

physios avatar Jan 13 '17 00:01 physios

It listens to ' \ ' pressed , but return keycode = '0' when checked using input processor , Strangely if we try it as

"if(Gdx.input.isKeyJustPressed(Keys.BACKSLASH)||Gdx.input.isKeyJustPressed(Keys.UNKNOWN))"

the method still does not work on Ubuntu , (key code of UNKNOWN being '0') Although , the keyCode obtained from InputProcessor , when passed into Keys.toString(int) returns "Unknown" , which shows that they key code matches with Keys.UNKNOWN.

hardik124 avatar Jan 18 '17 11:01 hardik124

Which backend is this? LWJGL 2 or 3?

intrigus avatar Jan 18 '17 12:01 intrigus

2

hardik124 avatar Jan 21 '17 09:01 hardik124

No updates on this?

physios avatar Aug 21 '18 09:08 physios

As seen here, justPressedKeys is not updated for keyCode of 0, which explains why your workaround with isKeyJustPressed(Keys.UNKNOWN) doesn't work.

What happens here is that libGDX has no known mapping from the Lwjgl reported keyCode to libGDX's keyCode, so it returns 0. I suspect that this happens because Lwjgl doesn't report the expected keyCode for backslash, but some other, possibly obscure, key. This happens often on foreign keyboard layouts (speaking from personal experience).

The solution would be to check which keyCode Lwjgl reports (try placing a breakpoint into the getGdxKeyCode(int) function), determining which key it really reports and creating the appropriate mapping in libGDX.

After that is done, you will have to listen to that code instead of BACKSLASH, but it should work.

Darkyenus avatar Aug 23 '18 19:08 Darkyenus

Same behaviour on LWJGL3. If I press the backslash key to the left of the Z key, I get a keyCode of 0. But when pressing the hash key to the left of Enter, I get 73 (backslash). Could this just be a keyboard layouts issue? In the United States layout, my backslash doesn't exist - notice how there is one fewer key.

UK US

I don't think this tells us anything, as the numbers don't align, but JavaScript uses code IntlBackslash (220) for my backslash. The American backslash is 222 (Chrome) or 163 (Firefox).

Frosty-J avatar Feb 08 '22 17:02 Frosty-J

Any news about this? I'm having the same behaviour, spacebar, arrow keys, escape... all returning as 0 on the InputProcessor.keyDown.

TADebastiani avatar Feb 23 '22 13:02 TADebastiani