2013-09-27 99 views

回答

0

我將繼承GUI組件的AccessibleContext,併爲它提供一個accessibleAction對象。使AccessibleContext.getAccessibleAction()返回您的對象。

如果它不爲空,它將爲屏幕閱讀器提供支持的操作列表,可以通過屏幕閱讀器調用doAction

0

這就是我爲我的項目所做的。創建一個基類API,將所有PInvokes調用到JAB WindowsAccessBridge DLL中。確保你的目標是正確的DLL名稱,如果你在64位操作系統上。使用getAccessibleContextFromHWND函數從Windows句柄中獲取VmID和Context。通過枚舉子項來查找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; 
}