Use Keyboard

Started by bbjam, September 16, 2008, 17:50:53

Previous topic - Next topic

bbjam

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)

Fool Running

Yes, you can't use the keyboard without some kind of display.

See Display.create()
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

bbjam

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?

Buggy

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.

Matzon

input creation is now done automatically when you create the display.

Buggy

So does calling Keyboard.create() create a second keyboard object? Or is calling it just good coding style, and no new object is created?

Matzon

If the keyboard hasn't been created, it wil create it - otherwise it will just do nothing.

Buggy

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?

Matzon

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

Buggy

Ah... thanks for clearing that up.