SendKeys {ENTER} to Webbrowser ( Note: SendKeys must send the key ONLY TO the Webbrowser ) Not outside of my application

Posted on 2007-08-07
Last Modified: 2013-12-25
Hello experts,

I have been working with a project around 1 month and i cannot find the solution to SendKeys {Enter} to the webbrowser , i have try SendKeys {Enter} , but it will send the key where your mouse are focus, I want to send key {ENTER} Only to my webbrowser, please find me a solution

I use vb6.0

Question by:KingSencat
    LVL 27

    Expert Comment

    What do you mean saying "WebBrowser"? Separate Internet Explorer window? All IE windows? Another browsers as well (NN, Opera etc)? Or webbrowser control inside your application?
    LVL 58

    Expert Comment

    You should identify the object in the DOM of your browser's current document and use the .Submit method.


    Much better that sending an {enter} key somewhere...


    Author Comment

    First COmment:Webbrowser control inside my application,,

    Second Comment:There is a special reason that i need it to do it with the Enter Button , someones know the way ?
    LVL 58

    Expert Comment

    Beg to differ, but I doubt that. The enter key on a page can have only three effects: insert a new line in a multi-line text box (like the one I'm typing in right now), following a hyperling, or activating the Submit of a button.

    Perhaps you are going to say that you want to launch some special code hooking the keyboard, but even that can be launched without using Sendkeys. A web page is a totally open object, in terms of contents and automation.

    But if you don't know enough about DOM and web pages, you can try the classical tricks of Sendkeys.
    1) play with the Wait parameter (second argument to Sendkeys)
    2) try to issue the Sendkeys *before* activating your browser

    Good luck!
    LVL 27

    Accepted Solution

    Please elaborate more a bit - from where do you want send key - your application?
    In this case:
    SendKeys "~"

    From other application (of from within your's but without changin focus)?
    In this case:
        PostMessage(wbHWND, WM_KEYDOWN, VK_RETURN, ByVal 0&)
        PostMessage(wbHWND, WM_KEYUP, VK_RETURN, ByVal 0&)
    where wbHWND is a handle to your WebBrowser control


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now