Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>SendKeys is not a good fit mainly due to:</p> <ul> <li>It can only send keys to active/focused application, which is never guaranteed to work because the the active application can change between the time the keys are actually sent.</li> <li>RDP and many other libraries (e.g., DirectX) block them mainly for security reasons.</li> </ul> <p>Better alternatives:</p> <ul> <li>Use <a href="http://msdn.microsoft.com/en-us/library/ms644950%28v=vs.85%29.aspx" rel="nofollow noreferrer"><code>SendMessage</code></a> or <a href="http://msdn.microsoft.com/en-us/library/ms646310%28VS.85%29.aspx" rel="nofollow noreferrer"><code>SendInput</code></a> for simple needs</li> <li>Some good examples of how to use SendMessage can be found: <ul> <li><a href="http://www.codeproject.com/KB/vb/Send_string_by_message.aspx" rel="nofollow noreferrer">Send strings to another application by using Windows messages</a></li> <li><a href="http://pinvoke.net/default.aspx/user32.SendMessage" rel="nofollow noreferrer">SendMessage via pInvoke</a> </li> <li><a href="http://www.blitzmax.com/Community/posts.php?topic=48863" rel="nofollow noreferrer">How To Send Keystrokes To Extern Win Application </a></li> </ul></li> <li>For more elaborate needs, it is recommended to use <a href="http://msdn.microsoft.com/en-us/library/ms731082.aspx" rel="nofollow noreferrer">WCF</a></li> <li>To get you started, read this <a href="http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication" rel="nofollow noreferrer">Basic Tutorial</a> that talks about Inter Process Communication</li> </ul> <p>Sample code using <a href="https://stackoverflow.com/questions/2113950/how-to-send-keystrokes-to-a-window"><code>SendMessage</code></a>:</p> <pre><code>HWND hwndNotepad = FindWindow(_T("Notepad"), NULL); HWND hwndEdit = FindWindowEx(hwndNotepad, NULL, _T("Edit"), NULL); SendMessage(hwndEdit, WM_SETTEXT, NULL, (LPARAM)_T("hello")); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload