The script puts temporary borders around, and gets text from, the element under the cursor.
It seems to always work correctly, however, if anyone notices an error or omission, or script issue, please comment below, because I would want something potentially widely used like this to be perfect. If anyone has written something similar, also, please inform me.
It uses 4 lots of SplashImage to show the borders around the element.
Code: Select all
#IfWinActive, ahk_class IEFrame
q:: ;internet explorer - get element under cursor
;show borders around, and get text from, element under cursor
;regardless of zoom percentage of 'Internet Explorer_Server' control
;it could potentially be incorporated into iWB2 Learner
IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"
CoordMode, Mouse, Screen
MouseGetPos, vMouseX, vMouseY,, hCtl, 3
WinGetClass, vCtlClass, % "ahk_id " hCtl
if !(vCtlClass == "Internet Explorer_Server")
return
if !(oDoc := ComObject(9,ComObjQuery(Acc_ObjectFromWindow(hCtl),IID_IHTMLWindow2,IID_IHTMLWindow2),1).document)
return
oWin := ComObject(9,ComObjQuery(oDoc,IID_IHTMLWindow2,IID_IHTMLWindow2),1)
oWB := ComObject(9,ComObjQuery(oWin,IID_IWebBrowserApp,IID_IWebBrowserApp),1)
vLogicalXDPI := oWB.document.parentWindow.screen.logicalXDPI
vDeviceXDPI := oWB.document.parentWindow.screen.deviceXDPI
vZoomRatio := vDeviceXDPI / vLogicalXDPI
;vWinX := oWin.screenLeft, vWinY := oWin.screenTop
;WinGetPos, vWinX2, vWinY2, vWinW2, vWinH2, ahk_class IEFrame
WinGetPos, vCtlX, vCtlY, vCtlW, vCtlH, ahk_id %hCtl%
vMouseX2 := (vMouseX-vCtlX)*(1/vZoomRatio)
vMouseY2 := (vMouseY-vCtlY)*(1/vZoomRatio)
oElt := oWin.document.elementFromPoint(vMouseX2, vMouseY2)
oRect := oElt.getBoundingClientRect()
vEltX := vCtlX + (oRect.left * vZoomRatio)
vEltY := vCtlY + (oRect.top * vZoomRatio)
vEltW := (oRect.right - oRect.left) * vZoomRatio
vEltH := (oRect.bottom - oRect.top) * vZoomRatio
JEE_Borders(vEltX, vEltY, vEltW, vEltH, 1000, "FFFF00")
MsgBox % oElt.tagName "`r`n" oElt.innerText
oDoc := oWin := oWB := oElt := oRect := ""
return
#IfWinActive
;==================================================
JEE_Borders(vPosX, vPosY, vPosW=0, vPosH=0, vTime=1000, vCol="FFFF00")
{
CoordMode, Pixel, Screen
vBorderH := 5 ;height of border
vBorderW := 5 ;width of border
SplashImage, 1:, % "B W" vPosW+(2*vBorderW) "H" vBorderH "X" vPosX-vBorderW "Y" vPosY-vBorderH "Cw" vCol,,, SP1 ;top
SplashImage, 2:, % "B W" vPosW+(2*vBorderW) "H" vBorderH "X" vPosX-vBorderW "Y" vPosY+vPosH "Cw" vCol,,, SP2 ;bottom
SplashImage, 3:, % "B W" vBorderW "H" vPosH+(2*vBorderH) "X" vPosX-vBorderW "Y" vPosY-vBorderH "Cw" vCol,,, SP3 ;left
SplashImage, 4:, % "B W" vBorderW "H" vPosH+(2*vBorderH) "X" vPosX+vPosW "Y" vPosY-vBorderH "Cw" vCol,,, SP4 ;right
Sleep % vTime
SplashImage, 1: Off
SplashImage, 2: Off
SplashImage, 3: Off
SplashImage, 4: Off
Return
}
;==================================================