Saturday, November 6, 2010

AHK (AutoHotKey) Script to control Dialog Box

iWeb_Init()
SetTitleMatchMode,2
ControlGet,hWnd,Hwnd,,Internet Explorer_Server1,ahk_class Internet Explorer_TridentDlgFrame
pDoc:=IE_GetDocument(hWnd)
pWin := iWeb_DomWin(pDoc)
COM_Invoke(pWin,"Document.all.item['btnID'].click")
COM_Release(pwin)
WinWaitClose, Web Page Dialog
SoundPlay, *64
Com_Release(pDoc)
iWeb_Term()
return

Note: the three indented lines can be replaced with
iWeb_clickDomObj(pDoc,"btnCancel")
accomplishes the same thing but I left the three lines in as a demonstration of how to inject javascript into an AHK script.(There isn't an iWeb function for everything)

Note: You have to #include COM.ahk and iWeb.ahk for this to work, and I commented out the MsgBox line in the COM_Error() function within COM.ahk in order to stop useless error messages from popping up. These libraries were not designed for dialog boxes, but they work, and the error messages just get in the way. Normally calling COM_Error(0) does the same thing except the iWeb functions keep calling COM_Error(1)

Note: ['btnID'] can be replaced with ['387'] or whatever the element index number is.
Notice the WinWaitClose to wait for the Dialog to close, and the Sound alert command. You can also use WinWait to just wait for the Web Browser Object to get focus.

1 comment:

  1. My "indented" lines were:
    pWin := iWeb_DomWin(pDoc)
    COM_Invoke(pWin,"Document.all.item['btnID'].click")
    COM_Release(pwin)

    ReplyDelete