manipulate input device

Hello,

What do i want to do?
I wanna manipulate the input device in general. That means i don't want to klick a button in a special program or window. I want to move my mouse and klick where it is and press the keyboard.

Why do i want this?
there is an older game where i wanna record some things for a game mod trailer. The game supports a free cam mod, but it's very difficult to get a smooth camera movement. So i wanna program the camera path, start the game and run the program for the camera movement.
i know with this request it would be possible to cheat in multiplayer games, but i promise i won't. i hate these cheaters.

What is my problem?
i found some code that i understand a bit:

<
SetCursorPos(5, 1075);
Sleep(1000);
INPUT MausKlick;

MausKlick.type = INPUT_MOUSE;

MausKlick.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1, &MausKlick, sizeof(MausKlick));

MausKlick.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1, &MausKlick, sizeof(MausKlick));>

everything works fine. the mouse jumps to start and klicks. But next the screen become black. So why does this happen??

Alternative i found this
https://msdn.microsoft.com/de-de/library/ms171548(v=vs.110).aspx
But i don't understand how the MouseEventArgs works.

Someone can point me out how to trigger mouse klicks??
closed account (48bpfSEw)
alternative try this: http://www.sikuli.org/
Thank you i'll take a look at it.
I got it working. I needed to overwrite the INPUT with zeros before reusing it.

But now i have a new Problem.

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
void keyHold(INPUT& ip, char key)
{
	SecureZeroMemory(&ip, sizeof(INPUT));
	ip.type = INPUT_KEYBOARD;
	ip.ki.wScan = 0;
	ip.ki.time = 0;
	ip.ki.dwExtraInfo = 0;

	ip.ki.wVk = key;
	ip.ki.dwFlags = 0;

	SendInput(1, &ip, sizeof(INPUT));

}

void keyRelease(INPUT& ip, char key)
{
	SecureZeroMemory(&ip, sizeof(INPUT));
	ip.type = INPUT_KEYBOARD;
	ip.ki.wScan = 0;
	ip.ki.time = 0;
	ip.ki.dwExtraInfo = 0;

	ip.ki.wVk = key;
	
	ip.ki.dwFlags = KEYEVENTF_KEYUP;

	SendInput(1, &ip, sizeof(INPUT));
}


These are my help functions and here my main code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main(int argc, char** argv)
{
	std::cout << "Hello" << std::endl;

	INPUT ip;

	SetCursorPos(20, 1060);
	Sleep(100);

	leftClick(ip);
	Sleep(1000);

	keyHold(ip, 'R');

	Sleep(5000);
	keyRelease(ip, 'R');

	system("pause");
	return 0;
}


What should happen?
mouse cursor jumps to start, klick and hold the 'r' for 5 seconds. So my windows search should be bumped by millions of r.

What happened?
there is only one r in the searchbar. Why is there only one r?? it is supposed to hold r for 5 seconds and after these 5 seconds the key should be released.
closed account (48bpfSEw)
sleep() freezes the process!

The architecture of Windows-Application base on sending Windows-Messages.
https://www-user.tu-chemnitz.de/~heha/petzold/ch06c.htm

To bump millions of "r" you have to send millions of WM_KEYDOWN messages and let them process through the system function WndProc(). In C++ Builder one have to call application->ProcessMessages() to handle all WM-Messages in the message queue.

You have only queued one key down event and then, five seconds later, one key up event.

SendInput() does not auto-repeat.

Topic archived. No new replies allowed.