How to create auto clicker+typer in C++ ??

Okay so what I want to do is :-
Create a program that can, say for example, switch to an already opened up google search page.
Type in a given string and press enter.

Once more.
The google search page is open.[Type anything on google.com and then THAT next page is the one ..]
**So , the search box ,where you enter text has fixed coordinates..
(Which website doesnt matter, only coordinates do!)

I want the mouse to go to those coordinates, *click* and now a cursor will appear on the search box.
After this I want to send a fixed string output...That is , it should actually type in the string in that search box.
then press enter.

That's it .
[P.S. - obviously I don't want to do this with google, that was just an example.]

Mini Algorithm-
1)Get the mouse pointer to the x-y coords
2)Click!
3)Type in the fixed string.
4)Enter..

I can put it in a loop, don't bother with the easy bits
I need to know how to control the mouse, and how to send the input string.
Code snippets would be perfect

Thank you !
For windows we use SendInput() for this kind of thing.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx

This is a code snippet that allow you to send any string as if was typed on the keyboard:
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
BOOL SendText( LPCTSTR lpctszText )
	{
	std::vector<INPUT> EventQueue;

	TCHAR Buff[120 * sizeof(TCHAR)] = {0};
	GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, Buff, sizeof(Buff));
	HKL hKeyboardLayout = ::LoadKeyboardLayout( Buff, KLF_ACTIVATE );

	const size_t Len = _tcslen( lpctszText );
	for( size_t Index = 0; Index < Len; ++Index )
		{
		INPUT Event = { 0 };

		const SHORT Vk = VkKeyScanEx(lpctszText[Index], hKeyboardLayout);
		const UINT VKey = ::MapVirtualKey( LOBYTE( Vk ), 0 );

		if( HIBYTE( Vk ) == 1 ) // Check if shift key needs to be pressed for this key
			{
			// Press shift key
			::ZeroMemory( &Event, sizeof( Event ));
			Event.type = INPUT_KEYBOARD;
			Event.ki.dwFlags = KEYEVENTF_SCANCODE;
			Event.ki.wScan = ::MapVirtualKey( VK_LSHIFT, 0 );
			EventQueue.push_back( Event );
			}

		// Keydown
		::ZeroMemory( &Event, sizeof( Event ));
		Event.type = INPUT_KEYBOARD;
		Event.ki.dwFlags = KEYEVENTF_SCANCODE;
		Event.ki.wScan = VKey;
		EventQueue.push_back( Event );

		// Keyup
		::ZeroMemory( &Event, sizeof( Event ));
		Event.type = INPUT_KEYBOARD;
		Event.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
		Event.ki.wScan = VKey;
		EventQueue.push_back( Event );

		if( HIBYTE( Vk ) == 1 )// Release if previously pressed
			{
			// Release shift key
			::ZeroMemory( &Event, sizeof( Event ));
			Event.type = INPUT_KEYBOARD;
			Event.ki.dwFlags = KEYEVENTF_SCANCODE| KEYEVENTF_KEYUP;
			Event.ki.wScan = ::MapVirtualKey( VK_LSHIFT, 0 );
			EventQueue.push_back( Event );
			}
		}// End for

	if( hKeyboardLayout )
		{
		UnloadKeyboardLayout( hKeyboardLayout );
		}

	return static_cast<BOOL>(::SendInput( static_cast<UINT>(EventQueue.size()), &EventQueue[0], sizeof( INPUT )));
	}


Topic archived. No new replies allowed.