Getting input without waiting for keypress

This is a discussion on Getting input without waiting for keypress within the C Programming forums, part of the General Programming Boards category; Greetings, Just so that I understand correctly, the programs provided at this link (as helpfully provided by Salem) are for ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    1

    Exclamation

    Greetings,

    Just so that I understand correctly, the programs provided at this link (as helpfully provided by Salem) are for programs that read one keypress at a time. Am I correct?

    If so, is it possible to have a C program that does other things while/without waiting for the user to press any key (e.g. check status of something)? Wasn't that the original question of this thread? Even with the programs listed, they still stop doing nothing while waiting for the user's input.

    Thanks to all for your patience on a relative newbie

    Anon48

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    Quote Originally Posted by Anon48
    Greetings,

    Just so that I understand correctly, the programs provided at this link (as helpfully provided by Salem) are for programs that read one keypress at a time. Am I correct?

    If so, is it possible to have a C program that does other things while/without waiting for the user to press any key (e.g. check status of something)? Wasn't that the original question of this thread? Even with the programs listed, they still stop doing nothing while waiting for the user's input.

    Thanks to all for your patience on a relative newbie

    Anon48
    ...Yes, it can. And that can be solved like this:

    If your compiler supports getch and kbhit (especially in Windows), you can do something like this:

    Code:
    int c;
    
    while ( true )
    {
    
    if ( kbhit() ) // if a key was hit ( returns non-zero - true), execute 'if' statment. else continue looping
    {
    
    // do this...
    c = getch();
    
    }
    
    };
    Some people will suggest not to do this because it's "non-standard". but, it's up to you if you want to continue using it. I, for one have used it before in my programs (without a problem)because it was the only way to get my program runing the way I wanted it to. If it works, why not.

    xeddiex.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There is no "standard" way to get a keystroke. Any method you ever do which can read a single keypress isn't going to be standard. You just have to find what works with your compiler.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 09:52 AM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 12:50 PM

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