Java Access Bridgeイベントを使用して、Java アプリケーションの UI コントロール (ボタン/編集ボックス/チェックボックスなど) からテキストをキャプチャできます。どうやって:
- 編集ボックスにテキストを設定する
- ボタンをクリックします
Java Access Bridge API 呼び出しを使用していますか?
Java Access Bridgeイベントを使用して、Java アプリケーションの UI コントロール (ボタン/編集ボックス/チェックボックスなど) からテキストをキャプチャできます。どうやって:
Java Access Bridge API 呼び出しを使用していますか?
これが私のプロジェクトで行った方法です。すべての 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;
}