The handle to the control.
The key to send to the window.
{
//We use FindWindow (a win32 api) to find a Notepad window.
//You must have an untitled notepad window open in order for this to work.
//We leave the classname NULL as we are only interested in the window title.
//The L before the "Untitled - Notepad" is only for Unicode projects.
HWND hWndParent = FindWindow(NULL, L"Untitled - Notepad");
//Now we need to find the edit-box part of the notepad window.
//Notice that we use FindWindowEx() here. This is because it is capable of searching
//for child windows. This time we search for classname instead of window title.
HWND hWnd = FindWindowEx(hWndParent, NULL, L"Edit", NULL);
//This is the character array we are going to send to Notepad.
BYTE keys[15] = "Hello DetourIt";
for (int i = 0; i < 15; i ++)
{
//Each iteration will send a new key to the Notepad window.
SendKey(hWnd, keys[i]);
}
//An exclamation mark for added effect.
SendKey(hWnd, '!');
}