PRO_gramista
PRO_gramista

Reputation: 922

Java program controlled by Console?

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?

Upvotes: 2

Views: 232

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285430

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.

Upvotes: 2

Related Questions