0 Replies - 483 Views - Last Post: 01 March 2013 - 01:39 AM Rate Topic: -----

#1 hawksprite  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 138
  • Joined: 11-September 09

Sending keystrokes to a webbrowser object.

Posted 01 March 2013 - 01:39 AM

I've been frustratingly trying to send keystroes to a webbrowser object in C#. But the catch is, is that It needs to continue functioning if the parent window loses focus. In short I can't just use the SendKeys method.

Here's what I have so far:

        private void button1_Click(object sender, EventArgs e)

        public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

        public void sendKeystroke()
            const uint WM_KEYDOWN = 0x100;
            const uint WM_KEYUP = 0x0101;
            IntPtr edit = webBrowser1.Handle;

            PostMessage(edit, WM_KEYDOWN, (IntPtr)(Keys.A), IntPtr.Zero);
            PostMessage(edit, WM_KEYUP, (IntPtr)(Keys.A), IntPtr.Zero);

This works when I switch the window handle to putty so I might be able to use it if I can get the browser to accept the messages posted to it.

Any suggestions? Could really use some help.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1