Input Grabber.......

This is a discussion on Input Grabber....... within the C Programming forums, part of the General Programming Boards category; hi... normal scanf(), gets(), getc() only wait for user to enter input and end when user press "Enter"..., but I ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    39

    Input Grabber.......

    hi...

    normal scanf(), gets(), getc() only wait for user to enter input and end when user press "Enter"...,

    but I wanted to know is there a function that active only if there is a keystroke from the keyboard........

  2. #2
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Try using

    GetAsyncKeyState(int Keycode);

    For example:

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main(void){
    bool WaitingForKey=true;
         while(WaitingForKey){
              if(GetAsyncKeyState(VK_SPACE)){
                   MessageBox(0,"You pressed SPACE!", "Hey",MB_OK);
                   WaitingForKey=false;
               }
         }
    getchar(); //Pause.
    return 0;
    }

  3. #3
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    212
    Well... most windows compliers supply function getch to do this, though getch is not standard function.
    Code:
    #include <conio.h> /* not a standard header file */
    
    int main( void )
    {
        getch();
    
        return 0;
    }

  4. #4
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    try kbhit() .

  5. #5
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    The OP never stated the platform.

    Please see http://faq.cprogramming.com/cgi-bin/...&id=1043284385 and the first question on http://www.eskimo.com/~scs/C-faq/s19.html.

    Preferably, read every FAQ entry there.

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    39
    Quote Originally Posted by cwr
    The OP never stated the platform.

    Please see http://faq.cprogramming.com/cgi-bin/...&id=1043284385 and the first question on http://www.eskimo.com/~scs/C-faq/s19.html.

    Preferably, read every FAQ entry there.

    Sorry, I'm using windows 2000 pro and microsoft Visual C++ 2003 .NET

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. Simple Console Input for Beginners
    By jlou in forum C++ Programming
    Replies: 0
    Last Post: 06-21-2005, 01:50 PM
  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