LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: bbjam on September 16, 2008, 17:50:53

Title: Use Keyboard
Post by: bbjam on September 16, 2008, 17:50:53
I'm trying to use the Keyboard class insted of Java's key events for my game engine, but when I try to .create() the keyboard I get
Exception in thread "main" java.lang.IllegalStateException: Display must be created.
at org.lwjgl.input.Keyboard.create(Keyboard.java:319)
at com.glassFlame.event.EventSystem.<init>(EventSystem.java:43)
at com.glassFlame.scene.SceneBuilder.createScene(SceneBuilder.java:19)
at com.glassFlame.util.setup.GameEngineFactory.createGameEngine(GameEngineFactory.java:16)
at test.TestFrame.<init>(TestFrame.java:88)
at test.TestFrame.main(TestFrame.java:38)
Title: Re: Use Keyboard
Post by: Fool Running on September 16, 2008, 19:25:00
Yes, you can't use the keyboard without some kind of display.

See Display.create()
Title: Re: Use Keyboard
Post by: bbjam on September 17, 2008, 00:05:48
By that I think you mean org.lwjgl.opengl.Display.

Big thanks :)

b.t.w. Is there any way to draw on the surface you get from Display.create() with Java2D?
Title: Re: Use Keyboard
Post by: Buggy on November 12, 2008, 03:37:36
I just made my very first OpenGL window, and keypresses seem to work without me having to call "Keyboard.create()" ... is this just a matter of style, or is it actually important?

I'm just using Keyboard.isKeyPressed() calls, by the way.
Title: Re: Use Keyboard
Post by: Matzon on November 12, 2008, 07:45:54
input creation is now done automatically when you create the display.
Title: Re: Use Keyboard
Post by: Buggy on November 12, 2008, 22:15:50
So does calling Keyboard.create() create a second keyboard object? Or is calling it just good coding style, and no new object is created?
Title: Re: Use Keyboard
Post by: Matzon on November 13, 2008, 08:32:31
If the keyboard hasn't been created, it wil create it - otherwise it will just do nothing.
Title: Re: Use Keyboard
Post by: Buggy on November 14, 2008, 23:38:31
Except, if I understand correctly, the keyboard can't be created without first creating a display. And creating a display automatically creates a keyboard, rendering Keyboard.create() completely useless.

Is there something I'm missing here?
Title: Re: Use Keyboard
Post by: Matzon on November 15, 2008, 00:15:27
a) its old code, hence no need to break stuff
b) you can disable automatic input creation using:
org.lwjgl.opengl.Display.nokeyboard
org.lwjgl.opengl.Display.nomouse
org.lwjgl.opengl.Display.noinput
Title: Re: Use Keyboard
Post by: Buggy on November 15, 2008, 04:03:38
Ah... thanks for clearing that up.