0

Is there a way to get the user input without GUI Listeners or Scanner class? Something like this:

if (Input.isKeyDown(KeyCode.VK_A)) {
    // Do something
}

In Unity3D you can get the Users input using this way.

Best regards Morph

2
  • Simply you cannot. To capture the events you need GUI controls. Commented Oct 14, 2013 at 13:36
  • Unity3D will be implimenting listeners or similar behind the scenes Commented Oct 14, 2013 at 13:38

3 Answers 3

1

Take a look at this page: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Input.Keys.html

You will find what you want.

Hope this helps!

EDIT: The link points to a page that contains an interface created for Input in some backends (desktop, GWT, etc.).

It may be useful for what you want.

Sign up to request clarification or add additional context in comments.

1 Comment

If you could explain why or how to use that link (or even what that link points to) this would be a much better answer
1
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;

public class KeyPressListener implements KeyListener {

    // when a key is pressed
    public void keyPressed(KeyEvent e){

        // the key you pressed
        char k = e.getKeyChar();

        // prints out what key you pressed
        System.out.println(k);   
    }

    // when a key is typed
    public void keyTyped(KeyEvent e){

    }

    // when a key is released
    public void keyReleased(KeyEvent e){

    }
}

this will get you keyboard input

Comments

0

You can only capture inputs in the context of your application. Else how could you know the user was not inputing on an other application?

In Java you can either use GUI (Swing or JavaFX) or console (System.in.read()) standard inputs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.