Jump to content

ActiveX/COM Focus Issue


zackrspv
 Share

Recommended Posts

Note, if i have multiple IE embeds using Shell.Explorer.2, the last one created steals all keyboard focus from the previous one. Is there a way to get it to ignore the keyboard focus input?

I tried to SetWinPOS to ignore zorder, noactivate, etc, but that didn't work.

I was tahinking of maybe adding an onclick or onfocus or onblur event handler to the head of the page in reference to the entire document, but i couldn't get that to work properly. I dunno if it would be good either, but it may be possible, perhaps, to capture those events, and when the window looses focus, to pass the HWND of the control (which is able to be gleaned by simple dom) to the event function, and then unfocus it.

Dunno.

This is really frustrating. My app has 5 ie windows in it (as they are chat viewers), and the focus is constantly being stuck.

Here's a simple reproducer, simply press tab while the top viewer has focus, you'll see it messes w/ the 2nd window, not the first one:

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

$hgui = GUICreate("test", 800, 600, -1, -1, $WS_CLIPCHILDREN+$WS_SYSMENU)
$oIE = _IECreateEmbedded()
$oIE2 = _IECreateEmbedded()
$oieax = GUICtrlCreateObj($oIE, 0, 0, 800, 300)
$oieax2 = GUICtrlCreateObj($oIE2, 0, 320, 800, 250)
GUISetState()
_IENavigate($oie, "http://www.google.com")
_IENavigate($oie2, "http://www.yahoo.com")


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case - 3
            Exit
    EndSwitch

WEnd

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

I tried adding:

$oIE2.document.releaseCapture
    $oIE.document.focus

as a test, but it still keeps the keyboard focus on the 2nd control :/

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

I also tried:

_winapi_SetWindowPos($hgui, $HWND_TOPMOST, 0, 0, 0, 0, $SWP_NOACTIVATE +$SWP_SHOWWINDOW +$SWP_NOMOVE+$SWP_NOSIZE)

TO no avail :/

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

have also tried:

_WinAPI_SetFocus($oIE)

Which clears the focus from the 2nd window to the first, but once you press tab, again, it messes w/ the 2nd box not the first. So it didn't set the focus right.

I did try to ensure i had the proper window too:

Local $aCall = DllCall("oleacc.dll", "int", "WindowFromAccessibleObject", "idispatch", $oIE, "hwnd*", 0)
$focus_MAIN = $aCall[2]
_WinAPI_SetFocus($focus_MAIN)
$oie.document.focus

But result is the same.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Interestingly enough,

Local $aCall = DllCall("oleacc.dll", "int", "WindowFromAccessibleObject", "idispatch", $oIE, "hwnd*", 0)
$focus_MAIN = $aCall[2]
Local $aCall = DllCall("oleacc.dll", "int", "WindowFromAccessibleObject", "idispatch", $oIE2, "hwnd*", 0)
$focus_OTHER = $aCall[2]
_WinAPI_SetFocus($focus_MAIN)
_WinAPI_EnableWindow($focus_OTHER, False)
_WinAPI_EnableWindow($focus_MAIN, True)

Stops the focus from being seen in the 2nd window, but still moves the window as if the controls are being highlighted. It's like it's just capturing the entire keyboard ... gah!

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Note, if i have multiple IE embeds using Shell.Explorer.2, the last one created steals all keyboard focus from the previous one. Is there a way to get it to ignore the keyboard focus input?

...

SNIP

...

Making some progress on this, it's cool that you can use event mode to be able to isolate when one Browser loses focus and the other gains. Using that, you could institute a focus() command to be able to unlock your keys.

It still does not stop the latest created Shell.Explorer.2 from hooking the keyboard, but with the focusin() and focusout() functions, you can set your focus to your desired object on those events.

For example, for me, i have a tab interface w/ 4 Shell.Explorer.2's, one per tab. I know what tab i'm on at any given time. So the focus commands, etc come in great use for me when i switch to my 5th box, which is an HTML editor com object (another IE instance). onfocusIN() allows me to release capture from my input box to the IE instance the tab is on, and onfocusOUT() allows me to switch focus back to my input box. This prevents the keys from being stuck.

The other function commands are useful as well. for example, onscroll() you could do another refocus to prevent stuck keys.

The example below ues many of the functions as informational, but the good one is the click and select start to show you what is highlighted in the FIRST box.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <array.au3>
Local $cRichEdit = ""
Local $cROBJ = "", $selStart = 0

$ui_name = GUICreate("Form1", 800, 600, 192, 124, BitOR($WS_CLIPCHILDREN, $WS_SYSMENU, $WS_MINIMIZEBOX, $WS_SIZEBOX))
GUISetBkColor(0x4d4d4d)
$button = GUICtrlCreateButton("test", 0, 380, 80, 20)

$oIE = _IECreateEmbedded ()
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 600, 250)

$oIE2 = _IECreateEmbedded ()
$GUIActiveX2 = GUICtrlCreateObj($oIE2, 0, 270, 600, 250)
GUISetState(@SW_SHOW)
_IENavigate ($oIE, "http://www.autoitscript.com")
$oBody = _IETagNameGetCollection($oIE, "body", 0)
ObjEvent($oBody, "_Evt_")

_IENavigate ($oIE2, "http://www.google.com")
$oBody2 = _IETagNameGetCollection($oIE2, "body", 0)
ObjEvent($oBody2, "_Evt_")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Evt_onscroll()
    ConsoleWrite("Scrolled:  "&@COM_EventObj & @CRLF)
EndFunc
Func _Evt_onblur()
    ConsoleWrite("Lost Focus:  "&@COM_EventObj & @CRLF)
EndFunc

Func _Evt_onclick()
    ConsoleWrite("Clicked:  "&@COM_EventObj & @CRLF)
    if $selStart = 1 then
        _IEAction($oie, "copy")
        _IEAction($oie, "unselect")
        MsgBox(0, "selected", ClipGet())
        $selStart = 0
    Else
        $selStart = 0
    EndIf

EndFunc
Func _Evt_ondrag()
    ConsoleWrite("Drag:  "&@COM_EventObj & @CRLF)
EndFunc
Func _Evt_onselectStart()
    ConsoleWrite("StartSelect:  "&@COM_EventObj & @CRLF)
    $selStart = 1
EndFunc
Func _Evt_onselectEnd()
    ConsoleWrite("EndSelect:  "&@COM_EventObj & @CRLF)
EndFunc
Func _Evt_onactivate()
    ConsoleWrite("Activated:  "&@COM_EventObj & @CRLF)
EndFunc
func _Evt_onbeforeactivate()
    ConsoleWrite("before activate" & @CRLF)
EndFunc
func _Evt_ondeactivate()
    ConsoleWrite("deactivated" & @CRLF)
EndFunc
func _Evt_onfocus()
    ConsoleWrite("focused" & @CRLF)
EndFunc
func _evt_onfocusIn()
    ConsoleWrite("focused in" & @CRLF)
EndFunc
func _evt_onfocusout()
    ConsoleWrite("focused out" & @CRLF)
EndFunc
func _evt_onmouseleave()
    ConsoleWrite("mouse leave" & @CRLF)
EndFunc
func _evt_oncontrolselect()
    ConsoleWrite("sel changed" & @CRLF)
EndFunc
Func _Evt_onmouseout()
    ConsoleWrite("Mouse out:  "&@COM_EventObj & @CRLF)
EndFunc

So there could still yet be a way to do this.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

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...