0

I can't seem to find any help for this problem.

For a standard cin, how can I have the program automatically input, as if I pressed the enter key, after the user stopped typing for 1.5 seconds?

  • 3
    Can't do that with just `cin`, sorry. It needs OS-specific ways or a library that wraps around those like ncurses. – Bartek Banachewicz Oct 20 '16 at 22:38
  • cin was simply a means of input. Is there a way to sense when typing has been static for 1.5 seconds? – K. Jackson Oct 20 '16 at 22:39
  • Try using a `std::stringstream` instead that way you can control the contents of the stream. I'll leave how to actually implement it up to you. – Captain Obvlious Oct 20 '16 at 22:39
  • I don't think a stringstream is going to help. What you need is unbuffered non-blocking input and a way to tell if a keypress is waiting. With Visual C++ you can use the functions in conio.h like kbhit() to check to see if a key has been pressed and to do something if when it hasn't. For unix there must be an equivalent to kbhit(). Maybe something like this will help: http://stackoverflow.com/questions/29335758/using-kbhit-and-getch-on-linux – Jerry Jeremiah Oct 20 '16 at 22:43
  • A couple other pages with code to detect when a key is pressed under unix: http://www.flipcode.com/archives/_kbhit_for_Linux.shtml http://cboard.cprogramming.com/c-programming/63166-kbhit-linux.html https://gcc.gnu.org/ml/gcc-help/2006-03/msg00101.html – Jerry Jeremiah Oct 20 '16 at 22:50

0 Answers0