0

So, I have this method (with nothing in it yet)

class Transmitter {
    public static void main(String[] args) {

    }
}

and I want to put a keylistener in it, to detect when the space key is pressed. I've looked at tutorials online, and they are all to complicated for my needs; I just want a simple "Print something in the console" when the space key is pressed. Thanks!

ByteDuck
  • 1,821
  • 3
  • 15
  • 27
  • Making a KeyListener is pretty simple, so if you think the tutorial is advanced, then you need to go back to the basics. – vallentin Nov 27 '13 at 16:54
  • I don't think you can have key listeners in console apps. You'll probably have to learn swing first. [You can emulate the behaviour by getting the raw console input](http://stackoverflow.com/questions/9545388/how-can-i-detect-arrow-keys-in-java-console-not-in-gui) but I doubt it's easier. – Zong Nov 27 '13 at 16:54
  • Key Listeners are usually added to the JFrames and such, or some object. I do not believe that it is possible to add KeyListener to console itself. – Quillion Nov 27 '13 at 16:54
  • A idea behind people asking about what code you have so far.. is a minimal working code (with errors and exceptions). You have just made a humor out of it :) – mtk Nov 27 '13 at 16:58

1 Answers1

0

As some others have commented, there is no concept of a key listener from a console application. If you just want to read input keys from the console, you can use System.in.read() within a loop: What is the use of System.in.read()?

Not sure if that's what you are looking for.

Community
  • 1
  • 1
MaQy
  • 478
  • 3
  • 10