Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 7 tasks
physios opened this issue Jan 12, 2017 · 8 comments

Comments

@physios
Copy link

physios commented Jan 12, 2017

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
  • Linux
  • MacOS
@physios physios changed the title Gdx.input.isKeyJustPressed(Keys.BACKSLASH), doesn't seem to work on Linux Mint 18 KDE Edition [Bug] Gdx.input.isKeyJustPressed(Keys.BACKSLASH), doesn't seem to work on Linux Mint 18 KDE Edition Jan 12, 2017
@physios physios changed the title [Bug] Gdx.input.isKeyJustPressed(Keys.BACKSLASH), doesn't seem to work on Linux Mint 18 KDE Edition [Bug] Gdx.input.isKey(Just)Pressed(Keys.BACKSLASH), doesn't seem to work on Linux Mint 18 KDE Edition Jan 12, 2017
@physios
Copy link
Author

physios commented Jan 13, 2017

Same code doesn't work on Ubuntu 16.01 LTS too

@hardik124
Copy link

hardik124 commented Jan 18, 2017

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.

@intrigus
Copy link
Contributor

Which backend is this?
LWJGL 2 or 3?

@hardik124
Copy link

2

@physios
Copy link
Author

physios commented Aug 21, 2018

No updates on this?

@Darkyenus
Copy link
Contributor

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.

@Frosty-J
Copy link
Contributor

Frosty-J commented Feb 8, 2022

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).

@TADebastiani
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants