Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send an "ENTER" key press to another application?

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)));
like image 431
JosephStyons Avatar asked Sep 16 '09 13:09

JosephStyons


People also ask

How do I send keystrokes to another app?

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.

How do you send SendKeys?

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)".

How do I use SendKeys SendWait?

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.


1 Answers

Try this

PostMessage(AppHandle, WM_KEYDOWN, VK_RETURN, 0);

Bye.

like image 57
RRUZ Avatar answered Oct 04 '22 21:10

RRUZ