I think he means he wants to receive keyboard/mouse events.
If you want to catch mouse clicks you can use WM_LBUTTONDOWN and WM_MBUTTONDOWN or WM_RBUTTONDOWN for the left mouse button, middle mouse button and right mouse buttons respectively.
You can use WM_KEYDOWN - then use a switch statement like this:
1 2 3 4 5 6 7 8 9 10 11
switch (message) /*this is the message you received after receiving a WM_KEYDOWN*/ {
case"VK_CONTROL": // (I'm not 100% if this is the actual keyname -- you can also use:)
//code
break;
case'A': // This is not case sensitive.
// code
break;
}
Not exactly what I meant, but that info will help to. Thanks.
What I mean is instead of pressing the up arrow to do something, have the program send the same command to the computer that the up arrow would normally. Basically like I am pressing a button, but I'm really not, the program is doing it. Is that possible? I don't think it is, but someone told me they did it before, and I was curious as to how.
Edit: To put it in clearer language (I hope) I want to simulate keyboard and mouse events. These events have to be sent to a different window though.
edit:
If it is what you are looking for there are a few examples of using it here (but otherwise it is not very well documented):
http://www.codeguru.com/forum/showthread.php?t=377394
Oh, that it similar to what I am trying to do - have the program 'press' the key.
You can easily send mouse events. I wrote this for a program I am currently writing (with no current purpose); it clicks random places. I'm not sure if the mouse click works as I have not tested it, but it should do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void clickloop() { // This function generates random x, y coords for the mouse to move to and click on that co-ordinate.
int x, y;
do {
srand((unsigned)time(0));
int random_integer;
int lowest=230, highest=730;
int range=(highest-lowest)+1;
x=lowest+int(range*rand()/(RAND_MAX + 1.0)); // Generate the x-coord...
y=lowest+int(range*rand()/(RAND_MAX + 1.0)); // ... and the y-coord.
SetCursorPos(x, y); // Move to the location demonstrated
// Send a mouse click event. As this Window does not exist the active window will be affected instead. Hopefully.
mouse_event(MOUSEEVENTF_LEFTDOWN|MOUSEEVENTF_LEFTUP, NULL, NULL, NULL, NULL);
} while (true);
}