1

So I have a small java game engine using a single JFrame.

I am currently using Key-Bindings as they were working neatly but I figured that a KeyListener might be architecturally more fitting.

But since I honestly don't really care which I'll use I wanted to ask if there is a performance difference between these or even a better option for getting keyboard input.

Thank you lots for your help!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • "*... I wanted to ask if there is a performance difference between these ...*" - Why not try it out? – Turing85 Aug 11 '19 at 21:25
  • Sure thing! How would you test it? I mean you can't really measure the time between key-press and the program registering the input... Do you have any tips? –  Aug 11 '19 at 21:27
  • question is: do you need hard numbers or does a subjective test suffice? If you need hard numbers, you could use a framework simulating key presses (see e.g. [this question](https://stackoverflow.com/questions/7745959/how-to-simulate-keyboard-presses-in-java)) and log the exact time the key is pressed and then log the time at which your program processed the event. – Turing85 Aug 11 '19 at 21:34
  • I mean as I said I don't care which I use so just the general idea of which one works faster is sufficient for me, I guess I'd be best to setup both and let each print when they registered the key.. –  Aug 11 '19 at 21:44

1 Answers1

0

After my consultation with Turing85 and some testing I figured out that the KeyListener is even up to 1ms faster than the binding.

==> If you go for performance KeyListener is your friend.