Quote (AbDuCt @ Oct 5 2014 08:20pm)
That's the windows api for you, deal with it.
You can pretty much forget doing anything meaningful with this as if you are trying to manipulate an application that has textboxes, you will only be able to send text to what ever is currently highlighted.
If you are trying to create automation you should sooner look into code caves and code injection into the running process and analysis their functions so that you may call them within their user space.
That's one of the main reasons to do it but I do have other reasons.
Anyways I did find a shorter solution but I would want to know if there's any other ways to do it, faster, best, stronger, more efficient.
Code
#define VK_ENTER 0x0D
#define VK_E 0x45
#define VK_K 0x4B
#define VK_L 0x4C
#define VK_Y 0x59
HWND WinActive(HWND window){
if (GetForegroundWindow() == window)
return window;
else
return 0;
}
HWND GetActive(){
return GetForegroundWindow();
}
int main()
{
HWND Notepad = FindWindow(TEXT("Notepad"), NULL);
HWND edit = FindWindowEx(Notepad, NULL, TEXT("Edit"), NULL);
int count = 1000;
while (count){
PostMessage(edit, WM_KEYDOWN, VK_K, 1);
PostMessage(edit, WM_KEYDOWN, VK_Y, 1);
PostMessage(edit, WM_KEYDOWN, VK_L, 1);
PostMessage(edit, WM_KEYDOWN, VK_E, 1);
PostMessage(edit, WM_KEYDOWN, VK_ENTER, 1);
--count;
}
}
And another solution someone told me was "SendMessage()". I haven't tested this one yet but it looks like it only works when the I want to type to is set as the active window.