2

I want to know if its possible to control my game with arrow keys. It is basic version of "2048" game as a console output. My idea:

if(arrowKeyRight is pressed)
{
  moveNumbersToRight
}

The same for the other arrow keys.

Is it possible for my program to read the arrow keys as an output?

4
  • and your question would be? Commented Aug 5, 2014 at 11:02
  • What is your question here ? Commented Aug 5, 2014 at 11:02
  • 1
    I want to know if its possible for my programm to read arrow keys as an output in console. if yes, how. many thanks! Commented Aug 5, 2014 at 11:03
  • 1
    Please, take a look at this question and replies stackoverflow.com/questions/17255549/… Commented Aug 5, 2014 at 11:05

1 Answer 1

2

If you're asking if you can use a KeyListener or similar construct from a standard Java console, then the answer is no since the standard Java console requires the user to press the enter key before keypresses are accepted. So for this to work, the user would have to press an arrow key and then press enter, but how do you respond if the user presses several different arrow keys and then enter? You can do this with 3rd party console libraries, such as Java Curses or with Java GUI programs.

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

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.