Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: LWJGL Keyboard-Inputs aren't recognized

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default LWJGL Keyboard-Inputs aren't recognized

    Hello,

    I wanted to create a simple window with the LWJGL and a key input request which closes the window.
    I also wanted to create the classes in seperated packages, so it's more organized.
    The window displays but if I press that certain key nothing happens.

    It would be great if you could help me.

    Thanks!

    Here is the Main class:

     
    package bb.main;
     
    import bb.input.Input;
    import bb.main.render.SimpleRenderer;
     
    public class Main {
    	public static void main(String[] args){
    		SimpleRenderer 	createWindow 	= new SimpleRenderer();
    		Input			input			= new Input();
     
    		createWindow.Render();
    		input.checkKey();
    	}
    }

    Here is the SimpleRenderer class:

    package bb.main.render;
     
    import org.lwjgl.LWJGLException;
    import org.lwjgl.opengl.Display;
    import org.lwjgl.opengl.DisplayMode;
     
    public class SimpleRenderer {
    	public void Render(){
     
    		try{
    			Display.setDisplayMode(new DisplayMode(1280, 720));
    			Display.setTitle("MISSING TITLE!");
    			Display.create();
    		} catch (LWJGLException LWex){
    			LWex.printStackTrace();
    			System.exit(0);
    		}
     
    		while(!Display.isCloseRequested()){
     
    			Display.update();
    		}
    		Display.destroy();
    	}	
    }


    And here is the Input class:
    package bb.input;
     
    import org.lwjgl.input.Keyboard;
    import org.lwjgl.opengl.Display;
     
    public class Input {
    	public void checkKey(){
    		while(Keyboard.next()){
    			if(Keyboard.getEventKeyState()){
    				if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
    					Display.destroy();
    					System.exit(0);
    				}	
    			}
    		}
    		Display.destroy();
    	}
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: LWJGL Keyboard-Inputs aren't recognized

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    Someone familiar with the LWJGL may come along to help, but notice the forum is generally geared towards helping with Java SE. All questions are welcome, but those about non-SE libraries may take a little longer to get a response. You might look for and ask your question in a LWJGL forum if one exists.

    Good luck!

Similar Threads

  1. Lock keyboard and mouse inputs
    By vaibhavi in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 12th, 2014, 01:11 PM
  2. [SOLVED] My MouseInputListener methods aren't being called.
    By stewbond in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 26th, 2013, 04:15 PM
  3. How do you define things from specific keyboard inputs?
    By JavaN00b101 in forum Java Theory & Questions
    Replies: 2
    Last Post: December 1st, 2011, 12:30 AM
  4. Formulas within my code aren't cooperating
    By bohrstein7 in forum What's Wrong With My Code?
    Replies: 15
    Last Post: September 2nd, 2011, 03:30 PM

Tags for this Thread