I have code that launches an external application and automatically fills in a password prompt.
I want to automate the pressing of the "ENTER" key, so that the user does not have to click "OK".
How can I send the ENTER key to an external application?
Below is my code as it stands right now.
The first line to post the password to the application works fine.
The second line to send an ENTER key press has no effect at all.
I am using Delphi 2010.
//now that we have the control handle, send the password to it
SendMessage(AppHandle,WM_SETTEXT,0,Integer(PChar(pwd)));
//and now push ENTER
SendMessage(AppHandle,WM_KEYDOWN,0,Integer(PChar(#13)));
There are two methods to send keystrokes to an application: SendKeys. Send and SendKeys. SendWait. The difference between the two methods is that SendWait blocks the current thread when the keystroke is sent, waiting for a response, while Send doesn't.
To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use "+(EC)".
Use SendWait to send keystrokes or combinations of keystrokes to the active application and wait for the keystroke messages to be processed. You can use this method to send keystrokes to an application and wait for any processes that are started by the keystrokes to be completed.
Try this
PostMessage(AppHandle, WM_KEYDOWN, VK_RETURN, 0);
Bye.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With