-
Sendkey to apps
Hi All,
I downloaded an app from a coding site to help me understand sending keystrokes to other apps, but I am having trouble with one aspect that is not included in the code.
Once I send the keystrokes to my target app I lose the focus on the sendkeystoapps application. I need to be able to send keys to another application, then wait a few minutes for them to be executed, then return to my app to perform further funtions. Is this even possible?
The sendkeystospps project can be found at http://codepaste.ru/3381/
Note: The sendkeystoapps is not my code. I am using it as a learning tool.
Thank you
-
Re: Sendkey to apps
you can use this piece of code after grabbing the window handle of the desired window.
Code:
::SendMessage(hwnd, WM_SYSCOMMAND, SC_HOTKEY, (LPARAM) hwnd);
::SendMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, (LPARAM) hwnd);
::ShowWindow(hwnd, SW_SHOW);
::SetForegroundWindow(hwnd);
::SetFocus(hwnd);
-
Re: Sendkey to apps
-
Re: Sendkey to apps
I would advise to use PostMessage instead SendMessage. If receiving application is ill behaving it may put your application into a zombie state.
Another advice is to use SendInput Function that synthesizes keystrokes and mouse action (movements, and button clicks).
All of the above would be helpful to you if you were in the right forum. It is a C++ forum not C#.