Instantaneous Input

This is a discussion on Instantaneous Input within the C++ Programming forums, part of the General Programming Boards category; How do you set it up to actively wait for a key press, and then use that key press. Instead ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    15

    Instantaneous Input

    How do you set it up to actively wait for a key press, and then use that key press. Instead of user typing the letter and hitting enter. I just want them to hit the key. Not have to hit enter as well.

    I tried

    getch()=input;
    switch(input)
    {
    case 'a':
    blah blah
    case 'b':
    blah blah
    }

    but you still have to hit enter after typing the letter.

    Also. how do you do the same thing as above except let them just hit enter to perform a function. I guess i'd need to know the value of the Enter key.

    Thanx ahead of time,
    Darkflame

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    char a;
    a=getch(); //in conio.h

    works for some compilers but there is no standard way. What o/s and compiler are you using?

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    I'm running WinMe & using Dec-C++

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    3
    Try this:

    #include <dos.h>

    char a;

    if(kbhit())
    {
    a = getch();
    cout<<a<<endl;
    }

  5. #5
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    For Dev C++ you have to include <conio_mingw.h> if you want to use getch() without have the input echoed on screen.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    In Microsoft Visual C++ you can use:

    Get a character from the console without echo (_getch) or with echo (_getche).

    int _getch( void );

    int _getche( void );

    with <conio.h>.

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, 12: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21