console problem, running in background

i have a program where you can use the a and s keys to do mouse clicks, but the console that this program runs in has to be "highlighted" or clicked on for this to work, so in other words, you can only use the keys once until you have to click on the console again. What i am looking for is a way for this program to run in the background, not invisable but still running when not clicked on. something similar to the on-screen keyboard that comes with most windows os's. this is the code i got so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <windows.h>
#include <winuser.h>
#include <iostream>
#include <conio.h>

int x;
int y;

void left_click()
{
    mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);
}

void right_click()
{
    mouse_event(MOUSEEVENTF_RIGHTDOWN, x, y, 0, 0);
    mouse_event(MOUSEEVENTF_RIGHTUP, x, y, 0, 0);
}

int main (){
        bool bDone = false;
	char cInput;
	while (bDone == false){
		cInput = _getch();
		switch (cInput) {
			case 'a':
			case 'A':
				left_click();
				break;

			case 's':
			case 'S':
				right_click();
				break;

			case 'q':
			case 'Q':
				bDone = true;
				break;
		}
	}
	return 0;
}


thanks ahead of time and for all commets =)

ps. i'm a hardcore noob so don't be super intense with your answer, i probably won't get what you mean at first.
From your description it is not clear what you want or you have misunderstood how Windows works (or maybe I have misunderstood). If your app hasn't focus, keystrokes will normally not be sent to it but to the other process that has keyboard focus. Standard windows behavior. The only way you can achieve "stealing" those keystrokes (AFAIK) is to install a Windows System hook and trap the keyboard strokes sending them to your app. However in your example above you are using keys a A and so on, what if somebody wants to use those keys for instance as menu shortcuts in another program? The bottom line is that you are then working on quite an advanced program.

ok, well maybe i'll pick this project up once i understand windows a bit more, thanks anyways
Topic archived. No new replies allowed.