Advertisement Jump to content
Sign in to follow this  

How To Get Keyboard Input - In Simple English ?

This topic is 1778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

 I am having trouble getting any kind of input from KeyListener - and can not find any good examples around.

 Could some one post a working, simplified & bare bones example on how to get this to work ?

 Here is my version - which does nothing useful .

Game Loop

public class GameLoop {
KeyBoard kb;
boolean RUN;

     public GameLoop(){
     RUN = true;
     kb = new KeyBoard();

          System.out.println(kb.getX() );


public class KeyBoard implements KeyListener{
int x = 0 ;
	public void keyPressed(KeyEvent e) {}
	public void keyReleased(KeyEvent e) { x ++;} 
	public void keyTyped(KeyEvent e) {}
public String getX(){return "" + x ;}

Edited by Shippou

Share this post

Link to post
Share on other sites

There is a reason I said "Simplified" and "Bare Bones" .

Linking to two articles on theory with overly complex and mostly irrelevant examples  DO NOT HELP.


 I figured out why the code I posted does not work - it  can be summed up in less than 10 words .

"Requires: extends JFrame that isFocusable(true) and has addKeyListener(this) envoked"

Edited by Shippou

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!