Sleep (x) makes the computer sleep

This is probably one of the strangest things I've encountered so far in C ++:

while(counter != stop_value)
{
    //Part A starting
    ip.ki.wVk = VK_RETURN;
    ip.ki.dwFlags = 0;
    SendInput(1, &ip, sizeof(INPUT));
    ip.ki.wVk = VK_RETURN;
    ip.ki.dwFlags = KEYEVENTF_KEYUP;
    SendInput(1, &ip, sizeof(INPUT));
    //Part A ending

    if (s == 2) counter++;
    else counter--;
    cout << counter; //for debugging
    Sleep(i);
}

Whenever I comment on β€œPart A”, it works correctly; the program sleeps for iseconds, depending on user input. However, as soon as I add an easy way to start the return key, it forces me to turn off the entire computer (AKA, the screen turns completely black for iseconds). I tried searching on the Internet, but I can not do anything about it.

. INPUT . s , ( ) 2 3. , 0, ( stop-value). , sleep , "" i . , s 3, ( ) , -, . , .

, ... , , ( ), , :

  • : counter = 0; stop_value = 21; s = 2; i = 1000;
  • , : counter = 20; stop_value = 0; s = 3; i = 1000;

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298(v=vs.85).aspx

+4
1

:)

ip INPUT_KEYBOARD? ZeroMemory ?

+1
source

All Articles