home
clear breadcrumbs
search
login
 
timer, keypress, thread
#include
#include
#include
#include
#include
#include
using namespace std; void timer_start(function
func, unsigned int interval) { thread([func, interval]() { while (true) { func(); this_thread::sleep_for(std::chrono::milliseconds(interval)); } }).detach(); } void do_something() { cout << "Some function doing something every 5 seconds" << endl; } int main() { timer_start(do_something, 5000); // parameter in miliseconds every 5 seconds cout << "Press escape to quit" << endl << endl; while (true) { if (GetAsyncKeyState(VK_ESCAPE) & 0x0001) { break; } } }