Thread: enterless input

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937

    enterless input

    How could I read input from a user without them having to press enter ( like being able to read the char from getch() ).
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    use kbhit in a while loop

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Please explain how that answers my question.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    something like this
    Code:
    while(TRUE)
    {
        if(kbhit())
        {
               //take action on the user input here
        }
    }
    I think this would work, if not add a ! infront of kbhit.
    This have also been explaind with a bunch of different flavors..search the board for kbhit and you will find a more indepth distcusion about user input.

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    I need to be able to read what the user put in. (cin without the enter)
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    It's not a standard function (there's no standard way to do what you're asking), but most compilers include some form of

    getch()

    in conio.h.

  7. #7
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Well, is there a way to read what was just input into the console?

    while(TRUE)
    {
    if(kbhit())
    {
    switch(whattheyputin)
    {etc}
    }
    }
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  8. #8
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Yes,

    char c;
    c=getch();

    but this depends on your compiler. Which one are you using?

  9. #9
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    sigh..... MSVC++

    It's probobly a bad thing being in the platform I'm in.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  10. #10
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    YAY! Works
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  11. #11
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Ok, just one more question. The program recognizes the arrow keys, but is it reading them as what they are? Should I use the assigned ASCII symbols to identify them?
    Last edited by CodeMonkey; 03-14-2002 at 05:48 PM.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  12. #12
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Solved.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-29-2007, 11:16 PM
  2. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  3. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  4. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  5. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 03:07 AM