Тема: AHK: Получение значения адресной строки в фаерфоксе через UIA
Тема для обсуждения "Получение значения адресной строки в фаерфоксе через UIA".
http://forum.script-coding.com/viewtopic.php?id=17664
Вы не вошли. Пожалуйста, войдите или зарегистрируйтесь.
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться
Тема для обсуждения "Получение значения адресной строки в фаерфоксе через UIA".
http://forum.script-coding.com/viewtopic.php?id=17664
Спасибо, будем изучать!
Но у меня не срабатывает, сейчас на десятке проверяю.
Возможно дело в названии адресной строки.
У меня называется "Search with Google or enter address".
А независимого от языка нет варианта?
Можно так попробовать.
setbatchlines -1
IUIAutomation := ComObjCreate(CLSID_CUIAutomation := "{ff48dba4-60ef-4201-aa87-54103eef594e}", IID_IUIAutomation := "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}")
oStates := [collapsed_focusable_haspopup := 0x40100400, expanded_focusable_haspopup := 0x40100200, focused_collapsed_focusable_haspopup := 0x40100404, focused_expanded_focusable_haspopup := 0x40100204]
SafeArray := ComObjArray(VT_UNKNOWN := 13, oStates.Count())
if (A_PtrSize = 4)
SafeArrayConditions := ComObject(0x2000|3, ComObjValue(SafeArray), 1)
else
SafeArrayConditions := ComObject(0x2000|0x14, ComObjValue(SafeArray), 1)
loop % oStates.Count()
{
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
NumPut(VT_I4 := 3, variant, 0, "ushort")
NumPut(oStates[A_Index], variant, 8, "int")
if (A_PtrSize = 4)
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_LegacyIAccessibleStatePropertyId := 30096, "int64", NumGet(variant, 0, "int64"), "int64", NumGet(variant, 8, "int64"), "ptr*", condition) ; IUIAutomation::CreatePropertyCondition
else
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_LegacyIAccessibleStatePropertyId := 30096, "ptr", &variant, "ptr*", condition) ; IUIAutomation::CreatePropertyCondition
SafeArrayConditions[A_Index-1] := condition
}
DllCall(NumGet(NumGet(IUIAutomation+0)+29*A_PtrSize), "ptr", IUIAutomation, "ptr", ComObjValue(SafeArrayConditions), "ptr*", condition1) ; IUIAutomation::CreateOrConditionFromArray
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
NumPut(VT_I4 := 3, variant, 0, "ushort")
NumPut(UIA_EditControlTypeId := 50004, variant, 8, "int")
if (A_PtrSize = 4)
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_ControlTypePropertyId := 30003, "int64", NumGet(variant, 0, "int64"), "int64", NumGet(variant, 8, "int64"), "ptr*", condition2) ; IUIAutomation::CreatePropertyCondition
else
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_ControlTypePropertyId := 30003, "ptr", &variant, "ptr*", condition2) ; IUIAutomation::CreatePropertyCondition
DllCall(NumGet(NumGet(IUIAutomation+0)+25*A_PtrSize), "ptr", IUIAutomation, "ptr", condition1, "ptr", condition2, "ptr*", conditions) ; IUIAutomation::CreateAndCondition
ObjRelease(condition1)
ObjRelease(condition2)
loop % oStates.Count()
ObjRelease(SafeArrayConditions[A_Index-1])
return
f11::
DllCall(NumGet(NumGet(IUIAutomation+0)+6*A_PtrSize), "ptr", IUIAutomation, "ptr", WinExist("A"), "ptr*", ElementFromHandle) ; IUIAutomation::ElementFromHandle
DllCall(NumGet(NumGet(ElementFromHandle+0)+5*A_PtrSize), "ptr", ElementFromHandle, "int", TreeScope_Descendants := 0x4, "ptr", conditions, "ptr*", element) ; IUIAutomationElement::FindFirst
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
DllCall(NumGet(NumGet(element+0)+10*A_PtrSize), "ptr", element, "int", UIA_ValueValuePropertyId := 30045, "ptr", &variant) ; IUIAutomationElement::GetCurrentPropertyValue
ObjRelease(element)
ObjRelease(ElementFromHandle)
msgbox % StrGet(NumGet(variant, 8, "ptr"), "utf-16")
return
Так работает. А какое здесь преимущество перед IAccessible?
В скорости поиска.
У IAccessible нет встроенных методов, а тут есть.
Например IUIAutomationElement::FindFirst.
Да, это должно ускорить, надо поизучать.
Последний код завершается с ошибкой.
Спасибо.
Изменил создание SafeArray.
setbatchlines -1
IUIAutomation := ComObjCreate(CLSID_CUIAutomation := "{ff48dba4-60ef-4201-aa87-54103eef594e}", IID_IUIAutomation := "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}")
oStates := [focusable_haspopup := 0x40100000, collapsed_focusable_haspopup := 0x40100400, expanded_focusable_haspopup := 0x40100200, focused_focusable_haspopup := 0x40100004, focused_collapsed_focusable_haspopup := 0x40100404, focused_expanded_focusable_haspopup := 0x40100204]
SafeArray := DllCall("oleaut32\SafeArrayCreateVector", "uint", VT_UNKNOWN := 13, "uint", 0, "uint", oStates.Count())
if (A_PtrSize = 4)
SafeArrayConditions := ComObject(0x2000|3, SafeArray, 1)
else
SafeArrayConditions := ComObject(0x2000|0x14, SafeArray, 1)
loop % oStates.Count()
{
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
NumPut(VT_I4 := 3, variant, 0, "ushort")
NumPut(oStates[A_Index], variant, 8, "int")
if (A_PtrSize = 4)
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_LegacyIAccessibleStatePropertyId := 30096, "int64", NumGet(variant, 0, "int64"), "int64", NumGet(variant, 8, "int64"), "ptr*", condition) ; IUIAutomation::CreatePropertyCondition
else
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_LegacyIAccessibleStatePropertyId := 30096, "ptr", &variant, "ptr*", condition) ; IUIAutomation::CreatePropertyCondition
SafeArrayConditions[A_Index-1] := condition
}
DllCall(NumGet(NumGet(IUIAutomation+0)+29*A_PtrSize), "ptr", IUIAutomation, "ptr", ComObjValue(SafeArrayConditions), "ptr*", condition1) ; IUIAutomation::CreateOrConditionFromArray
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
NumPut(VT_I4 := 3, variant, 0, "ushort")
NumPut(UIA_EditControlTypeId := 50004, variant, 8, "int")
if (A_PtrSize = 4)
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_ControlTypePropertyId := 30003, "int64", NumGet(variant, 0, "int64"), "int64", NumGet(variant, 8, "int64"), "ptr*", condition2) ; IUIAutomation::CreatePropertyCondition
else
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_ControlTypePropertyId := 30003, "ptr", &variant, "ptr*", condition2) ; IUIAutomation::CreatePropertyCondition
DllCall(NumGet(NumGet(IUIAutomation+0)+25*A_PtrSize), "ptr", IUIAutomation, "ptr", condition1, "ptr", condition2, "ptr*", conditions) ; IUIAutomation::CreateAndCondition
ObjRelease(condition1)
ObjRelease(condition2)
DllCall("oleaut32\SafeArrayDestroy", "ptr", SafeArray)
return
f11::
DllCall(NumGet(NumGet(IUIAutomation+0)+6*A_PtrSize), "ptr", IUIAutomation, "ptr", WinExist("A"), "ptr*", ElementFromHandle) ; IUIAutomation::ElementFromHandle
DllCall(NumGet(NumGet(ElementFromHandle+0)+5*A_PtrSize), "ptr", ElementFromHandle, "int", TreeScope_Descendants := 0x4, "ptr", conditions, "ptr*", element) ; IUIAutomationElement::FindFirst
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
DllCall(NumGet(NumGet(element+0)+10*A_PtrSize), "ptr", element, "int", UIA_ValueValuePropertyId := 30045, "ptr", &variant) ; IUIAutomationElement::GetCurrentPropertyValue
ObjRelease(element)
ObjRelease(ElementFromHandle)
msgbox % StrGet(NumGet(variant, 8, "ptr"), "utf-16")
return
Угу, работает. ComObjValue(SafeArrayConditions) — это сам SafeArray и есть.
Вначале я его создавал так
SafeArray := ComObjArray(VT_UNKNOWN := 13, oStates.Count())
Сейчас так:
SafeArray := DllCall("oleaut32\SafeArrayCreateVector", "uint", VT_UNKNOWN := 13, "uint", 0, "uint", oStates.Count())
Я думал это одно и тоже, а похоже, что нет.
ComObjValue(SafeArrayConditions) — это сам SafeArray и есть.
Я имею в виду, что можно так:
DllCall(NumGet(NumGet(IUIAutomation+0)+29*A_PtrSize), "ptr", IUIAutomation, "ptr", SafeArray, "ptr*", condition1)
Вначале я его создавал так
Да, я стал смотреть и тоже подумал, что так должно работать, но почему-то не выходит.
Ещё так можно:
SafeArray := DllCall("oleaut32\SafeArrayCreateVector", "uint", VT_UNKNOWN := 13, "uint", 0, "uint", oStates.Count())
loop % oStates.Count()
{
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
NumPut(VT_I4 := 3, variant, 0, "ushort")
NumPut(oStates[A_Index], variant, 8, "int")
if (A_PtrSize = 4)
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_LegacyIAccessibleStatePropertyId := 30096, "int64", NumGet(variant, 0, "int64"), "int64", NumGet(variant, 8, "int64"), "ptr*", condition) ; IUIAutomation::CreatePropertyCondition
else
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_LegacyIAccessibleStatePropertyId := 30096, "ptr", &variant, "ptr*", condition) ; IUIAutomation::CreatePropertyCondition
NumPut(condition, NumGet(SafeArray + 8 + A_PtrSize) + A_PtrSize*(A_Index - 1))
}
DllCall(NumGet(NumGet(IUIAutomation+0)+29*A_PtrSize), "ptr", IUIAutomation, "ptr", SafeArray, "ptr*", condition1) ; IUIAutomation::CreateOrConditionFromArray
Понял, что было с SafeArray не так, нужно было флаг F_OWNVALUE удалить:
setbatchlines -1
IUIAutomation := ComObjCreate(CLSID_CUIAutomation := "{ff48dba4-60ef-4201-aa87-54103eef594e}", IID_IUIAutomation := "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}")
oStates := [focusable_haspopup := 0x40100000, collapsed_focusable_haspopup := 0x40100400, expanded_focusable_haspopup := 0x40100200, focused_focusable_haspopup := 0x40100004, focused_collapsed_focusable_haspopup := 0x40100404, focused_expanded_focusable_haspopup := 0x40100204]
SafeArray := ComObjArray(VT_UNKNOWN := 13, oStates.Count())
ComObjFlags(SafeArray, -1) ; Remove F_OWNVALUE
pSafeArray := ComObjValue(SafeArray)
loop % oStates.Count()
{
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
NumPut(VT_I4 := 3, variant, 0, "ushort")
NumPut(oStates[A_Index], variant, 8, "int")
if (A_PtrSize = 4)
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_LegacyIAccessibleStatePropertyId := 30096, "int64", NumGet(variant, 0, "int64"), "int64", NumGet(variant, 8, "int64"), "ptr*", condition) ; IUIAutomation::CreatePropertyCondition
else
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_LegacyIAccessibleStatePropertyId := 30096, "ptr", &variant, "ptr*", condition) ; IUIAutomation::CreatePropertyCondition
NumPut(condition, NumGet(pSafeArray + 8 + A_PtrSize) + A_PtrSize*(A_Index - 1))
}
DllCall(NumGet(NumGet(IUIAutomation+0)+29*A_PtrSize), "ptr", IUIAutomation, "ptr", pSafeArray, "ptr*", condition1) ; IUIAutomation::CreateOrConditionFromArray
NumPut(VT_I4 := 3, variant, 0, "ushort")
NumPut(UIA_EditControlTypeId := 50004, variant, 8, "int")
if (A_PtrSize = 4)
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_ControlTypePropertyId := 30003, "int64", NumGet(variant, 0, "int64"), "int64", NumGet(variant, 8, "int64"), "ptr*", condition2) ; IUIAutomation::CreatePropertyCondition
else
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", UIA_ControlTypePropertyId := 30003, "ptr", &variant, "ptr*", condition2) ; IUIAutomation::CreatePropertyCondition
DllCall(NumGet(NumGet(IUIAutomation+0)+25*A_PtrSize), "ptr", IUIAutomation, "ptr", condition1, "ptr", condition2, "ptr*", conditions) ; IUIAutomation::CreateAndCondition
ObjRelease(condition1)
ObjRelease(condition2)
DllCall("oleaut32\SafeArrayDestroy", "ptr", pSafeArray)
return
f11::
DllCall(NumGet(NumGet(IUIAutomation+0)+6*A_PtrSize), "ptr", IUIAutomation, "ptr", WinExist("A"), "ptr*", ElementFromHandle) ; IUIAutomation::ElementFromHandle
DllCall(NumGet(NumGet(ElementFromHandle+0)+5*A_PtrSize), "ptr", ElementFromHandle, "int", TreeScope_Descendants := 0x4, "ptr", conditions, "ptr*", element) ; IUIAutomationElement::FindFirst
VarSetCapacity(variant, 8+A_PtrSize*2, 0)
DllCall(NumGet(NumGet(element+0)+10*A_PtrSize), "ptr", element, "int", UIA_ValueValuePropertyId := 30045, "ptr", &variant) ; IUIAutomationElement::GetCurrentPropertyValue
ObjRelease(element)
ObjRelease(ElementFromHandle)
msgbox % StrGet(NumGet(variant, 8, "ptr"), "utf-16")
return
Точно.
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться