Results 1 to 7 of 7
  1. #1
    Sreejesh25 is offline Member
    Join Date
    Apr 2008
    Location
    Banglore,India
    Posts
    4
    Rep Power
    0

    Question getting each character from keyboard

    I want to read each character from the keyborad to do some action on each key.
    But the System.in.read() was waiting for ENTER key to be pressed.
    I want System.in.read() returning one character each time I'm pressing one character on the keyboard.
    Please help...
    The code is like this.

    int ch;
    while ('\n' != (ch = System.in.read())) {
    System.out.println("You pressed " + ch
    + ".System waiting for next character.Press ENTER to exit");
    }



    System.in.read() should not wait for the user to press the ENTER key.

  2. #2
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    This is an interesting question.

    I have searched for ages trying to find the answer but it appears that you can't get anything from System.in without the 'enter' key being pressed. Unfortunately it doesn't seem possible. :confused:
    Did this post help you? Please me! :cool:

  3. #3
    persikaspacesen Guest

    Default Wild granny and mature

    Collection of maturess

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You could use Swing and listen for key events.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Old zombie thread

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Blast. Note to self - check the date.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  7. #7
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    305
    Rep Power
    6

    Default

    Indeed, and as the rabbit ages and matures they tend to hop around playfully in the sun.

Similar Threads

  1. getting each character from keyboard
    By Sreejesh25 in forum New To Java
    Replies: 11
    Last Post: 01-25-2011, 01:08 PM
  2. Polled keyboard input through swing
    By Prometheus in forum Advanced Java
    Replies: 2
    Last Post: 02-04-2008, 04:05 PM
  3. Assign a keyboard key to a JButton.
    By gszauer in forum AWT / Swing
    Replies: 1
    Last Post: 12-15-2007, 10:42 PM
  4. reading text character by character
    By bugger in forum New To Java
    Replies: 2
    Last Post: 11-09-2007, 08:54 PM
  5. Help with keyboard events?
    By Bibendum in forum New To Java
    Replies: 2
    Last Post: 11-02-2007, 02:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •