public static AccessibleContextInfo GetAccessibleContextInfo(Int32 vmID, IntPtr ac) { AccessibleContextInfo aci = new AccessibleContextInfo(); //This will be the info that we return. // Allocate global memory space for the size of AccessibleContextInfo and store the address in acPtr IntPtr acPtr = Marshal.AllocHGlobal(Marshal.SizeOf(new AccessibleContextInfo())); try { //Convert the pointer to an actual object. Marshal.StructureToPtr(new AccessibleContextInfo(), acPtr, true); //getAccessibleContextInfo() returns true or false, depending on whether it succeeds. if (JabApi.getAccessibleContextInfo(vmID, ac, acPtr)) { aci = (AccessibleContextInfo)Marshal.PtrToStructure(acPtr, typeof(AccessibleContextInfo)); //Check that the info isn't null, and then return. if (!ReferenceEquals(aci, null)) { return(aci); } } } catch { return(new AccessibleContextInfo()); } return(new AccessibleContextInfo()); }
public static AccessibleTreeItem GetComponentTree(IntPtr hWnd, out Int32 vmID) { screenContents.Clear(); screenContentsString = string.Empty; AccessibleTreeItem accessibleTreeItem = new AccessibleTreeItem(); vmID = 0; if (JabApi.isJavaWindow(hWnd) == 1) { unsafe { IntPtr acPtr; if (JabApi.getAccessibleContextFromHWND(hWnd, out vmID, out acPtr)) { AccessibleContextInfo ac = new AccessibleContextInfo(); accessibleTreeItem = GetAccessibleContextInfo(vmID, acPtr, out ac, null, 0, string.Empty); // RECURSION SEED return(accessibleTreeItem); } } } return(null); }
// 追加分 public static Boolean GetAccessibleActions(Int32 vmID, IntPtr AccessibleContext, out AccessibleActions accessibleActions) { accessibleActions = new AccessibleActions(); IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(accessibleActions)); Marshal.StructureToPtr(accessibleActions, ptr, true); Boolean ret = JabApi.getAccessibleActions(vmID, AccessibleContext, ptr); accessibleActions = (AccessibleActions)Marshal.PtrToStructure(ptr, typeof(AccessibleActions)); return(ret); }
public static AccessibleTextItemsInfo GetAccessibleTextInfo(Int32 vmID, IntPtr ac) { //Reserve memory IntPtr ati = Marshal.AllocHGlobal(Marshal.SizeOf(new AccessibleTextItemsInfo())); //Call DLL. JabApi.getAccessibleTextItems(vmID, ac, ati, 0); //Creat object AccessibleTextItemsInfo atInfo = (AccessibleTextItemsInfo)Marshal.PtrToStructure(ati, typeof(AccessibleTextItemsInfo)); //Free memory if (ati != IntPtr.Zero) { Marshal.FreeHGlobal(ati); } return(atInfo); }
public static Boolean DoAccessibleActions(Int32 vmID, IntPtr AccessibleContext, string action) { AccessibleActionsToDo actionTodo = new AccessibleActionsToDo(); actionTodo.actionsCount = 1; actionTodo.actions = new AccessibleActionInfo[32]; actionTodo.actions[0].name = action; IntPtr ptrActionTodo = Marshal.AllocHGlobal(Marshal.SizeOf(actionTodo)); Marshal.StructureToPtr(actionTodo, ptrActionTodo, true); Int32 failure = -1; Boolean ret = JabApi.doAccessibleActions(vmID, AccessibleContext, ptrActionTodo, ref failure); if (failure >= 0) { return(false); } return(ret); }
private static AccessibleTreeItem GetAccessibleContextInfo(Int32 vmID, IntPtr currentPtr, out AccessibleContextInfo currentContext, AccessibleTreeItem parentItem, int level, string lineage) { unsafe { // Allocate global memory space for the size of AccessibleContextInfo and store the address in acPtr IntPtr acPtr = Marshal.AllocHGlobal(Marshal.SizeOf(new AccessibleContextInfo())); try { Marshal.StructureToPtr(new AccessibleContextInfo(), acPtr, true); if (JabApi.getAccessibleContextInfo(vmID, currentPtr, acPtr)) { currentContext = (AccessibleContextInfo)Marshal.PtrToStructure(acPtr, typeof(AccessibleContextInfo)); if (!ReferenceEquals(currentContext, null)) { AccessibleTreeItem newItem = BuildAccessibleTree(currentContext, parentItem); if (!ReferenceEquals(newItem, null)) { //Checks to see if current object has any text items. if (currentContext.accessibleText == true) { AccessibleTextItemsInfo textItem; //Gets text items. textItem = GetAccessibleTextInfo(vmID, currentPtr); newItem.textValue = textItem.sentence; string treeInfo = Repeat("\t", level) + currentContext.name + " = \"" + textItem.sentence + "\""; screenContentsString += treeInfo + Environment.NewLine; Debug.Print(treeInfo); } else { string treeInfo = Repeat("\t", level) + currentContext.name; screenContentsString += treeInfo + Environment.NewLine; Debug.Print(treeInfo); } //Start collecting children int nextLevel = level + 1; for (int i = 0; i < currentContext.childrenCount; i++) { string lineageInfo = Repeat("\t", level) + level.ToString() + " Child " + i.ToString() + " Lineage = {" + lineage + "}"; screenContentsString += lineageInfo + Environment.NewLine; Debug.Print(lineageInfo); string currentlineage; if (lineage == string.Empty) { currentlineage = i.ToString(); } else { currentlineage = lineage + ", " + i.ToString(); } if (currentContext.role_en_US != "unknown" && currentContext.states_en_US.Contains("visible")) // Note the optomization here, I found this get me to an acceptable speed { AccessibleContextInfo childContext = new AccessibleContextInfo(); IntPtr childPtr = JabApi.getAccessibleChildFromContext(vmID, currentPtr, i); GetAccessibleContextInfo(vmID, childPtr, out childContext, newItem, nextLevel, currentlineage); //TODO: Not sure when or where to release the java objects, the JVM will leak memory until released //JabApi.releaseJavaObject(vmID, childPtr); } } } return(newItem); } } else { currentContext = new AccessibleContextInfo(); } } finally { if (acPtr != IntPtr.Zero) { Marshal.FreeHGlobal(acPtr); } //TODO: Not sure when or where to release the java objects, the JVM will leak memory until released //JabApi.releaseJavaObject(vmID, currentPtr); } } return(null); }
// Windows_runはメッセージポンプが必要 // https://stackoverflow.com/questions/50582769/windowsaccessbridge-for-java-automation-using-c-sharp public static void Init() { JabApi.Windows_run(); DoEvents(); }