0
Button & Timer
How do I create a script capable to read a char in a limited time, e. g., 3 seconds? if any char has been taken in this period, it assumed a default value and prosecute the rest of the code. C++ or C#
3 Respostas
+ 1
idk if its possible, but you can try to create a timed thread with cin in it, just a idea not sure if it will work
0
you can record the time when the user need to type the input and after the input, then compare both the time and see if the different less than 3 second or not here an example
//untested
char input;
clock_t start_time = clock();
int wait_time = 3;
cin >> input;
if((clock() - start_time) <= (wait_time*1000)){
//user complete to input in less than or equal 3 second
}else{
//user fail to input
}
0
I will try it... but I think it will stop the line "cin>> input;" eternally, until someone press the keyboard enter.
I want this, but, if the function wait for 3 seconds or more, a default value is given to input