3

Java Access Bridgeイベントを使用して、Java アプリケーションの UI コントロール (ボタン/編集ボックス/チェックボックスなど) からテキストをキャプチャできます。どうやって:

  1. 編集ボックスにテキストを設定する
  2. ボタンをクリックします

Java Access Bridge API 呼び出しを使用していますか?

4

2 に答える 2

8

これが私のプロジェクトで行った方法です。すべての PInvokes を JAB WindowsAccessBridge DLL に呼び出す基本クラス API を作成します。64 ビット OS を使用している場合は、適切な DLL 名をターゲットにしていることを確認してください。getAccessibleContextFromHWND 関数を使用して、Windows ハンドルから VmID とコンテキストを取得します。子を列挙して、Java ウィンドウ内のテキストボックスまたはボタンを見つけます。探しているコントロールを見つけたら、TextBox または Button がアクションを実行します。

1) テキストを設定する

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;

    }

    return sbText.ToString().TrimEnd();
}

2) ボタンをクリックします

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");
}

芯...

public API.AccessBridgeVersionInfo VersionInfo
{
    get { return GetVersionInfo(this.VmId); }
}

public API.AccessibleContextInfo Info
{
    get { return GetContextInfo(this.VmId, this.Context); }
}

public Int64 Context
{
    get;
    protected set;
}

public Int32 VmId
{
    get;
    protected set;
}
于 2014-04-18T21:33:53.150 に答える