pradeep,krishna has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks.

I am trying to send the string "PRADEEP" with {ENTER} key at the end to a text box in a login form. I have to press ENTER to make the login credentials to be validated.

So i used WMSetText(1,"PRADEEP{X}") where {X} is one of these{\n,\x0D,\r,\cr,\015,\012}... But none of it worked. I know that I can use SendKeys() function by taking the cursor focus into the text box. But if i use it i need to bring that form to foreground, and I want my process to be completed without coming to foreground.

Please Assist me in solving this.

Thanks in advance.

Pradeep Krishna :)

  • Comment on Sending The key {ENTER} using WMSetText function in win32 module.

Replies are listed 'Best First'.
Re: Sending The key {ENTER} using WMSetText function in win32 module.
by marto (Cardinal) on Feb 13, 2014 at 10:25 UTC

    If you are talking about the Win32::GuiTest module (please be specific when posting, How do I post a question effectively?) SendKeys "Sends keystrokes to the active window as if typed at the keyboard", I added the empahsis to this quote. You can't use this to send keystrokes to windows which are not active.

    The Win32::GuiTest method WMSetText is an interface to WM_SETTEXT, which also only sets the text of an active Window. This is not a perl or Win32::GuiTest specific thing. This is how the interface is designed.

    Update: Please read the following conversation in the responses below. Thanks Anonymous Monk.

      um, no , you linked the postmessage constant, which can be used with a hwnd which is not active

      the guitest docs say  $set = WMSetText($hwnd,text) where $hwnd is the id of the window

      Its not unlike hwndSendKeys

      win32 is for real programmer -- there is nobody to help :D

        I'm sure OP would appreciate a short but complete example illustrating how this can be achieved. Thanks. Apologies, I've never found MSDN documentation to be great to use :)