我目前正在使用 IAccessible 并尝试自动单击并做一些事情。
它适用于几个 Pushbuttons、Splitbutton 和其他元素。
最后一个元素是 Windows 系统设置,它是 ROLE_SYSTEM_PUSHBUTTON。
accDoDefaultAction 被忽略,与窗口句柄的 SendMessage 和 PostMessage 相同。
虚拟代码:
private void SetAutoSettingTest()
{
var RootWindowses = GetWindowsByName("Settings", "ApplicationFrameWindow");
foreach (var RootWindows in RootWindowses) {
var AccessableChild = MSAA.GetAccessibleObjectFromHandle(RootWindows.windowHandle);
var IAccessibleLinkList = new List<IAccessible>();
MSAA.GetAccessibleObjectListByRole(AccessableChild, "PushButton", ref IAccessibleLinkList, true);
foreach (var IAccessibleCheckButton in IAccessibleLinkList) {
AppendLog("Item in Settings AccessableButtonList (found)");
if (IAccessibleCheckButton.get_accName(0).Equals("MySetting"))
// it found the proper IAccessible Object. Verified
{
Thread.Sleep(1000); // Just waited if the dialog was not finished WM_PAINT
IAccessibleCheckButton.accSelect(0); // Was just a try, but didnt help
IAccessibleCheckButton.accDoDefaultAction(0); // Is ignored
var MyHandle = MSAA.GetHandle(IAccessibleCheckButton);
AppendLog("HWND=" + MyHandle ); // It was a IntPtr (HWND)
int IAccessibleLeft = 0, IAccessibleTop = 0, IAccessibleWidth = 0, IAccessibleHeight = 0;
IAccessibleCheckButton.accLocation(out IAccessibleLeft, out IAccessibleTop, out IAccessibleWidth, out IAccessibleHeight, 0);
Win.ShowWindow(RootWindows.windowHandle, Win.SW_SHOW); // just in cae it was minimized
Win32.BringWindowToTop(MyHandle ); // just in case the Element to toggle was somehow in background
Win.SetCursorPos(IAccessibleLeft, IAccessibleTop); // Used Mousepos and clicks which works, but not a clean solution
Win.mouse_event(Win.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Win.mouse_event(Win.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
AppendLog(String.Format("Location Left {0} Top {1} Width {2} Height {3}", IAccessibleLeft, IAccessibleTop, IAccessibleWidth, IAccessibleHeight)); // valid data
}
}
}
}
它返回一个 HWND,但即使是到 HWND 的 PostMessage 也会被忽略。
Role 是ROLE_SYSTEM_PUSHBUTTON
StateSTATE_SYSTEM_FOCUSABLE
和 childId CHILDID_SELF
。这意味着它可以被访问并且通常被切换。它不是只读的。