Jump to content

send keys to embedded InternetExplorer ?


Recommended Posts

Hi guys. I have a question regarding Internet Explorer and SendMessage/SendKey.

Basically I created a gui with embedded internet explorer.

...
$gui=GuiCreate($g_szVersion,@DesktopWidth-100,@DesktopHeight-100,-1,-1,$WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$ie=_IECreateEmbedded()
$ie_hwnd = GUICtrlGetHandle("[CLASS:Internet Explorer_Server; INSTANCE:1]")
;ConsoleWrite("_IEPropertySet silent: "&_IEPropertySet($ie,"silent",true)&@CRLF)
;ConsoleWrite("_IEPropertySet statusbar: "&_IEPropertySet($ie,"statusbar",true)&@CRLF)
$ieActiveX=GUICtrlCreateObj($ie,0,0,@DesktopWidth-100,@DesktopHeight-100)
_IENavigate ($ie,"about:blank")
GUISetState(@SW_SHOW,$gui)
...

I try to send keystrokes to it (f.ex. UP and DOWN for scrolling, STRG+/STRG- for zooming, ...), but whatever I try, I fail :) .

I tried it with ControlSend, Send, _SendMessage. I just can't get it right. So, what can I do ?

Thanks in advance :) .

Edited by MartinMerten
Link to comment
Share on other sites

Found an example in another thread, which I modified. Still no luck.

What it should to:

-open a gui

-create embedded ie

-load a page

-send 10x the key {DOWN} to make IE scroll down in the thread

#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

_IEErrorHandlerRegister()

$oIE = _IECreateEmbedded()
$hGUI = GUICreate("myWindow", 800, 600, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 800, 600)
GUISetState();Show GUI

_IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?showtopic=82184")
$oSubmit = _IEGetObjByName ($oIE, "r_go")
_IEAction ($oSubmit, "focus")
for $i=1 to 10
    ConsoleWrite("sending command:"&ControlSend($hGUI, "", $GUIActiveX, "{DOWN}")&@CRLF)
    sleep(1000)
next

The ControlSend doesn't work though, ControlSend returns a 0.

Link to comment
Share on other sites

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

There is one other option.

The main problem is how to get control handle of the embedded object.

You can do it like this:

#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


_IEErrorHandlerRegister()

$oIE = _IECreateEmbedded()
$hGUI = GUICreate("myWindow", 800, 600, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 800, 600)
GUISetState();Show GUI

_IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?showtopic=82184")


;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Get control handle
Global $hHandle = _GetObjectWinHandle($oIE)
ConsoleWrite("--- " & $hHandle & @CRLF)
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

; Focus it
$oIE.document.focus


For $i = 1 To 10

    #cs
        $oIE.document.parentwindow.scrollBy(500, 500) ; DaleHohm's suggestion
        Sleep(1000)
    #ce

    ConsoleWrite("sending command:" & ControlSend($hHandle, 0, 0, "{DOWN}") & @CRLF)
    Sleep(1000)

Next





Func _GetObjectWinHandle($oObject)

    Local $aCall = DllCall("oleacc.dll", "int", "WindowFromAccessibleObject", _
            "idispatch", $oObject, _
            "hwnd*", 0)

    If @error Or $aCall[0] Then
        Return SetError(1, 0, 0)
    EndIf

    Return $aCall[2]

EndFunc   ;==>_GetObjectWinHandle

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...