LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: ThorPrime on June 26, 2006, 21:11:04

Title: Ghost Keyboard events?
Post by: ThorPrime on June 26, 2006, 21:11:04
I've been calling the following lines every tenth of a second in my game:
while(Keyboard.next())

   notifyKeyListeners();

and for some reason, if one holds down a key or sometimes just not pressing the button very fast, random keyboard events occur.

Keyboard.next() should only return true when a key has been pushed down or let up correct?

This occurs on all OSes.
(but is worst under linux, bad under windows, and occasional under mac)
Title: Re: Ghost Keyboard events?
Post by: ThorPrime on June 27, 2006, 02:54:42
Fixed it.
It looks like the problem was that one thread was calling keyboard.next while another was calling Dispaly.update().

Synchronizing the two threads fixed it.
Title: Ghost Keyboard events?
Post by: Matzon on June 27, 2006, 06:27:25
Generally, lwjgl isn't thread safe. So if you choose to use multiple threads anyway - you will have to synchronize yourself, like you already did.
Title: Ghost Keyboard events?
Post by: darkprophet on June 27, 2006, 11:42:43
I believe 1.0b1 added a few functions in Display to help in such cases..

Mainly Display.swapBuffers(); (i think) to only update the window and not poll the keyboard/mouse...

DP