KeyBindings vs KeyListeners

I’m so confused about Keyboard input in Java games. Everytime I look up something like “Keyboard input for Java games”, I get these examples and tutorials that use KeyListeners. Then, everytime I look up issues I’m having, people say that you should use Key Bindings. But, there are no Key Binding tutorials besides Oracle’s over complicated one.

If it’s constantly suggested to use key bindings over keyListeners, then why are all examples/tutorials using keylisteners?

Hi

You need an API based on events (with listeners, like in NEWT, AWT, Swing, SWT, QtJambi, …) or a polling API (like JInput) to implement key bindings anyway.

Well, yes. But, you can still use KeyListeners without KeyBindings.

Who the hell told you to use key bindings? XD

You do want to use KeyListeners.

Well, I was having focusing issues when using KeyListeners. Everything I searched for game me people saying that the proper way was to use KeyBindings, then they would link the oracle tutorial.

you should post some code. I’m sure this is actually a problem of terminology. A keylistener is a part of code, in swing a thread, which waits for hardware keyboard inputs and forwards them to your code. Keybindings are simple “what key does which action”. “Key SPACE jumps” :point: that is a “binding”

No you can’t, you have to tell what to do when a key is pressed, released, typed, you have to run an action depending on a key, that’s a key binding.