Send key presses to background application window

Announcements and discussion for PInvoke

Send key presses to background application window

Postby Hooch » Sun May 29, 2011 9:42 am

Can you help me to transfer that code to C#?

Code: Select all
    HWND Notepad = FindWindowEx( GetDesktopWindow( ), 0, "Notepad", 0 );
    SendMessage( GetDlgItem( Notepad, MB_TYPEMASK ), WM_SETTEXT, 0, (LPARAM)"Hello Notepad, what's up?" );

Thank you in advance

I want to send key presses to background window.
I don't want to use SendKeys.Send because I want that window to be in background.
SendKeys requires that window is active.
Posts: 1
Joined: Sun May 29, 2011 9:40 am

Postby Brian Donahue » Tue May 31, 2011 8:46 am

You can find the signatures for both functions on Once you insert the signature suggested by PInvoke, you can use both native functions from C#, for example:
Code: Select all
    public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
You'll also want to read the notes carefully on the PInvoke page for that function.
Brian Donahue
Posts: 6590
Joined: Mon Aug 23, 2004 9:48 am

Postby twain » Fri Nov 25, 2011 5:05 am

Well, I too had been recently working on this one. First of all, you need to search for the signatures for the two functions. The link for that has been given here by Brian. After you insert the signature, you can effectively use both of the native functions in C#. Has anyone used Port 25? Are they good in email delivery solutions?
Posts: 2
Joined: Mon Nov 14, 2011 4:21 am

Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests