Sending Keypresses while not active(NOT for a key logger)

Hi, whenever the program runs and I click off of it, it stops changing caps lock. Is there a way to ensure it's always running until it's closed?
(Note: I know I'm using bad libraries and things like getch(). I will be changing that later, so I don't need help with that)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <stdio.h>


int main(){

    char buffer = 1;
    while((int)buffer != 0){
        INPUT input[2];
        ::ZeroMemory(input, sizeof(input));
        input[0].type = input[1].type = INPUT_KEYBOARD;
        input[0].ki.wVk  = input[1].ki.wVk = VK_CAPITAL;
        input[1].ki.dwFlags = KEYEVENTF_KEYUP;  // THIS IS IMPORTANT
        ::SendInput(2, input, sizeof(INPUT));
        buffer = getch();
        std::cout << buffer;
    }

    return 0;
}
Topic archived. No new replies allowed.