0

在 C# 中的 Java Access Bridge上工作了一段时间。我终于开始工作了,部分。

  • 我可以正确初始化访问网桥。
  • 我可以使用 GetAccessibleContextFromHWND 来获取 vmid 和 javaObjectHandle。
  • 我也可以使用GetAccessibleContextInfo 来获取accessibleContextInfo。
  • 最后,我可以枚举孩子并找到我感兴趣的节点。

我如何从那里拿走它? 我尝试执行设置文本、单击或获取文本等操作,但无法执行。 我使用了另一个问题中提到的以下代码,Automation using Java Access Bridge

设置文字:

public string Text
{
    get 
    {
        return GetText();
    }
    set
    {
        if (!API.setTextContents(this.VmId, this.Context, value))
            throw new AccessibilityException("Error setting text");
    }
}

private string GetText()
{
    System.Text.StringBuilder sbText = new System.Text.StringBuilder();

    int caretIndex = 0;

    while (true)
    {
        API.AccessibleTextItemsInfo ti = new API.AccessibleTextItemsInfo();
        if (!API.getAccessibleTextItems(this.VmId, this.Context, ref ti, caretIndex))
            throw new AccessibilityException("Error getting accessible text item information");

        if (!string.IsNullOrEmpty(ti.sentence))
            sbText.Append(ti.sentence);
        else               
            break;

        caretIndex = sbText.Length;

    }

点击一个按钮:

public void Press()
{
    DoAction("click");
}

protected void DoAction(params string[] actions)
{
    API.AccessibleActionsToDo todo = new API.AccessibleActionsToDo()
    {
        actionInfo = new API.AccessibleActionInfo[API.MAX_ACTIONS_TO_DO],
        actionsCount = actions.Length,
    };

    for (int i = 0, n = Math.Min(actions.Length, API.MAX_ACTIONS_TO_DO); i < n; i++)
        todo.actionInfo[i].name = actions[i];

    Int32 failure = 0;
    if (!API.doAccessibleActions(this.VmId, this.Context, ref todo, ref failure))
        throw new AccessibilityException("Error performing action");
}

任何想法将不胜感激。谢谢!!

4

1 回答 1

0

doAccessibleActions实际上这个功能根本不起作用,所以,你必须结合win32 api来做替代品,比如:set text=> send key,滚动......

于 2020-02-18T04:06:38.283 回答