How to intercept a key stroke in a Java console app?

Discussion in 'Java' started by chirs, Apr 10, 2004.

  1. chirs

    chirs Guest

    How to intercept a key stroke in a Java console application? The key
    strokes are entered in the DOS window. I need to discard all the key
    strokes except the Enter key. When a use type other keys, nothing
    will happen. When he presses the Enter key, the program will
    continue.

    Thank you very much.

    Chris
     
    chirs, Apr 10, 2004
    #1
    1. Advertising

  2. chirs

    Chris Smith Guest

    chirs wrote:
    > How to intercept a key stroke in a Java console application? The key
    > strokes are entered in the DOS window. I need to discard all the key
    > strokes except the Enter key. When a use type other keys, nothing
    > will happen. When he presses the Enter key, the program will
    > continue.


    If you use BufferedReader.readLine() and ignore the actual contents of
    the return value, you can accomplish this. If you're looking for a way
    to prevent the keys from appearing on the screen, though, then I'm
    afraid you've exceeded the capabilities of pure Java. Java is not
    designed for writing console-mode user interfaces, and very few non-
    trivial things are possible if you try.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Apr 10, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KO
    Replies:
    1
    Views:
    372
    Andrew Thompson
    Jan 21, 2004
  2. Petra Neumann

    The Shape of a Stroke

    Petra Neumann, Mar 21, 2005, in forum: Java
    Replies:
    6
    Views:
    917
    Jim Sculley
    Mar 23, 2005
  3. Angus
    Replies:
    5
    Views:
    2,240
    Michael Rauscher
    Nov 18, 2006
  4. Keyboard stroke for EOF ?

    , Jul 18, 2006, in forum: C Programming
    Replies:
    4
    Views:
    477
    Keith Thompson
    Jul 18, 2006
  5. chris
    Replies:
    3
    Views:
    138
    chris
    Nov 25, 2004
Loading...

Share This Page