Here is how I did it for my project. Create a base class API that calls all PInvokes in the JAB WindowsAccessBridge DLL. Make sure you configure the correct DLL name if you are using 64-bit operating systems. Use the getAccessibleContextFromHWND function to get the VmID and context from the Windows Handle. Locate the text box or button in the Java window by listing the children. After you find the control you are looking for, in your case the TextBox or Button performs the action.
1) Set the text
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) Press the button
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"); }
The main ...
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; }
02Anant
source share