+ 10
Delay .. screen wait ...
How to make the execution wait in C++ for about 2 seconds ? I want the user wait on the screen and want the next line to display after about 2 seconds ? Is there some command for it ? please tell syntax and header file . I know that this could be done by looping but it will then wait differently every time .So need a better method .
8 Respostas
+ 14
@Sahaj You’ll need to start by downloading and installing AutoHotkey, which is a simple scripting language that allows you to create easy scripts. Once you do that, right-click anywhere and choose New –> AutoHotkey Script.
Once you’ve done that, paste the following into the script:
#Persistent
SetTimer, PressTheKey, 1800000
Return
PressTheKey:
Send, {Space}
Return
This simple script will wait every 30 minutes and press the Spacebar. You can adjust the 1800000 number above to the amount of milliseconds required. So, for example, if you wanted it to run every 2 minutes, you’d use 60 seconds * 2 minutes * 1000 milliseconds = 120000 total milliseconds.
Save the file name as whatever you’d like, and then double-click on it to run it.
You can also send another hotkey or any number of characters just by changing the Send, {Space} line to something else—you can literally type out some letters you want to send, or you can use some of the special keys on the AutoHotkey documentation page. For example, to make it send the word “lazy” and then press the Space bar, you could use:
Send,lazy{Space}
+ 15
I made it in Java though!
+ 11
Simple method for Windows, include <windows.h> and do Sleep(2000). Console pauses for 2000ms = 2 seconds.
+ 5
1 save the time at user input
2 loop through an empty while until the difference between the current time and the time of the input equals 2secons or 2000ms
3 continue your program as you like after the time wasting while loop
#include <time.h>
clock() gives you the current time in ms
http://www.cplusplus.com/reference/ctime/clock
+ 3
Thanks everyone .
@seamiki Your third method is the best i will be using that in my program . Thanks.😊
+ 3
@seamiki
Well i had asked for help from dayve on a project and he posted it here so to thank him i gave him best answer Xp .
+ 2
@Sahaji Bamba if so, you could have marked it as best answer. Anyway glad it was helpful.
+ 1
You can try sleep_for, from <thread>, using time units from <chrono>.
More here (simple example given): http://www.cplusplus.com/reference/thread/this_thread/sleep_for/