Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created January 11, 2015 23:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumatti1/e79470659289db1d4734 to your computer and use it in GitHub Desktop.
Save kumatti1/e79470659289db1d4734 to your computer and use it in GitHub Desktop.
Yahoo!
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Declare PtrSafe _
Function IUnknown_QueryService Lib "shlwapi.dll" ( _
ByVal punk As IUnknown, _
guidService As GUID, _
riid As GUID, _
ppvOut As IAccessible _
) As Long
Private Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Const MOUSEEVENTF_LEFTDOWN = &H2
Private Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As LongPtr)
Sub hoge()
Dim IID_IAccessible As GUID
With IID_IAccessible
.Data1 = &H618736E0
.Data2 = &H3C3D
.Data3 = &H11CF
.Data4(0) = &H81
.Data4(1) = &HC
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H38
.Data4(6) = &H9B
.Data4(7) = &H71
End With
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www.yahoo.co.jp/"
While ie.busy Or ie.ReadyState <> 4
DoEvents
Wend
ie.document.all("srchtxt").Value = "hoge"
Dim btn As MSHTML.IHTMLInputElement
Set btn = ie.document.all("srchbtn")
Dim hr As Long
Dim pElement As MSHTML.IHTMLElement
Set pElement = btn
Dim acc As IAccessible
hr = IUnknown_QueryService(pElement, IID_IAccessible, IID_IAccessible, acc)
'Debug.Print acc Is Nothing, Hex(hr)
If hr < 0 Then Exit Sub
Const CHILDID_SELF = 0&
Dim x&, y&, cx&, cy&
acc.accLocation x, y, cx, cy, CHILDID_SELF
'btn.Focus
SetCursorPos x + 10, y + 10
mouse_event MOUSEEVENTF_LEFTDOWN, x + 10, y + 10, 0, 0
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment