In my Windows command line program, I'm waiting for the user to press the left shift and left click keys simultaneously to continue the execution of the rest of the program. The command prompt will not be in focus when the key combo is pressed.
My current code is:
#include <iostream>
#include <windows.h>
int main()
{
std::cout << "Press left shift and left click to start\n";
// GetKeyState() returns 0 or 1 when key is not pressed, and -127 or -128 when key is pressed
while (GetKeyState(VK_LSHIFT) >= 0 || GetKeyState(VK_LBUTTON) >= 0) {
;
}
std::cout << "Starting\n";
}
The current code works. However, when waiting for the user to enter the key combo, CPU utilisation of a single core is at 100%.
Is there a non-CPU intensive way of waiting for the user to enter a key combo?