本文介绍了使用java访问桥功能,除了“setTextContents”之外,Everything似乎都能正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我们正在使用Java Access Bridge(Windows访问桥DLL)尝试将文本发送到java窗口的字段。我们初始化了A.P.I.,成功检测到了一个java窗口(这只能在第二次调用isJavaWindow函数时正常工作)。我们可以通过getAccessibleContextFromHWND获取可访问的上下文。然后我们使用上下文来递归孩子,直到我们找到有问题的文本框。我们可以使用getTextInfo函数来读取字段的内容,getAccessibleContextInfo函数返回良好的数据。我可以看到该字段的属性可通过accessibleContextInfo数据结构进行编辑,但setTextContents函数始终返回false。这是C#中的代码片段用法(我们也尝试过使用Autoit)A.P.I。版本2.0.2 public 部分 类 Form1:表格 { public Form1() { InitializeComponent(); } private void button1_Click( object sender,EventArgs e) { // 枚举窗口 JavaAPIFunc.Windows_run(); bool found = false ; Int32 VmId = 0 ; AccessibleContext Ac = new AccessibleContext(); AccessibleContextInfo Info = new AccessibleContextInfo(); foreach (KeyValuePair< intptr,> lWindow in OpenWindowGetter.GetOpenWindows()) { IntPtr lHandle = lWindow.Key; string lTitle = lWindow.Value; if (JavaAPIFunc.isJavaWindow((HWND)lHandle)) { MessageBox.Show( 找到一个java窗口); JavaAPIFunc.getAccessibleContextFromHWND(lHandle, out VmId, out Ac); found = true ; break ; } } 如果(找到) { TraverseTheBullshitInterface(VmId,Ac ); } } private AccessibleContext TraverseTheBullshitInterface( Int32 VmId,AccessibleContext AccessContext) { AccessibleContextInfo Info = new AccessibleContextInfo(); AccessibleTextItemsInfo TextInfo = new AccessibleTextItemsInfo(); JavaAPIFunc.getAccessibleContextInfo(VmId,AccessContext, ref 信息); if (Info.name == 用户名:&& Info.role_en_US == text) { JavaAPIFunc.getAccessibleTextItems(VmId,AccessContext, ref TextInfo, 0 ); if (!JavaAPIFunc.setTextContents(VmId,AccessContext, test)) { throw new 异常( 错误设置文本); } } for ( int i = 0 ; i < Info.childrenCount; ++ i) { TraverseTheBullshitInterface(VmId,JavaAPIFunc.getAccessibleChildFromContext(VmId,AccessContext,i)); } return AccessContext; } } 数据结构:< pre lang = cs> public 枚举 WABAPI {MAX_STRING_SIZE = 1024 ,SHORT_STRING_SIZE = 256 ,MAX_BUFFER_SIZE = 10240 } [StructLayout(LayoutKind.Sequential,CharSet = CharSet。自动)] public struct AccessibleContextInfo { [MarshalAs( UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.MAX_STRING_SIZE)] public 字符串名称; // 对象的AccessibleName [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.MAX_STRING_SIZE)] public string 描述; // 对象的AccessibleDescription [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.SHORT_STRING_SIZE)] public string 角色; // 本地化AccesibleRole字符串 [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.SHORT_STRING_SIZE)] public string role_en_US; // en_US语言环境中的AccesibleRole字符串 [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.SHORT_STRING_SIZE)] public 字符串状态; // 本地化AccesibleStateSet字符串(以逗号分隔) [MarshalAs(UnmanagedType.ByValTStr,SizeConst = ( int )WABAPI.SHORT_STRING_SIZE)] public string states_en_US; // en_US语言环境中的AccesibleStateSet字符串(以逗号分隔) public Int32 indexInParent; // 父对象的索引 public Int32 childrenCount; // 子项数量(如果有) public Int32 x; // 屏幕坐标(以像素为单位) public Int32 y; // public Int32 width; // 对象的像素宽度 public Int32 height; // 对象的像素高度 public Boolean accessibleComponent; // 各种附加标志 public Boolean accessibleAction; // Java可访问性接口 public Boolean accessibleSelection; // 如果此对象不 public Boolean accessibleText; // 实现附加接口 // 有问题 // BOOL accessibleValue; //旧BOOL指示是否支持AccessibleValue public Boolean accessibleInterfaces; // 包含其他接口标志的新位域 } [ StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public struct AccessibleTextInfo { public Int32 charCount; // 此文本对象中的字符数 public Int32 caretIndex; // 插入符号索引 public Int32 indexAtPoint; } [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public struct AccessibleTextItemsInfo { [MarshalAs(UnmanagedType.ByValTStr,SizeConst = 1 )] public String letter; [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.SHORT_STRING_SIZE)] public 字符串字; [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.MAX_STRING_SIZE)] public 字符串句子; } [StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public struct AccessibleTextAttributesInfo { public Boolean 大胆; public Boolean italic; public Boolean 下划线; public Boolean 删除线; public Boolean 上标; public Boolean 下标; [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.SHORT_STRING_SIZE)] public String backgroundColor; [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.SHORT_STRING_SIZE)] public String foregroundColor; [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.SHORT_STRING_SIZE)] public String fontFamily; public Int32 fontSize; public Int32 alignment; public Int32 bidiLevel; public Single firstLineIndent; public Single leftIndent; public Single rightIndent; public Single lineSpacing; public Single spaceAbove; public Single spaceBelow; [MarshalAs(UnmanagedType.ByValTStr,SizeConst =( int )WABAPI.MAX_STRING_SIZE)] public String fullAttributesString; } 原型导入: [返回:MarshalAs(UnmanagedType.Bool)] [DllImport( WindowsAccessBridge-64.dll,CallingConvention = CallingConvention.Cdecl,ThrowOnUnmappableChar = true ,CharSet = CharSet.Unicode)] public extern static bool setTextContents( Int32 vmID,AccessibleContext accessibleContext, string text); 解决方案 < pre lang = c# > [返回:MarshalAs(UnmanagedType.Bool)] [DllImport(WindowsAccessBridge-64.dll ,CallingConvention = CallingConvention.Cdecl,ThrowOnUnmappableChar = true,CharSet = CharSet.Unicode)] public extern static bool setTextContents(Int32 vmID,AccessibleContext accessibleContext,string text); < / pre > 应该是: < pre lang = c# > [返回:MarshalAs(UnmanagedType.Bool)] [DllImport(WindowsAccessBridge-64 .dll,CallingConvention = CallingConvention.Cdecl,ThrowOnUnmappableChar = true,CharSet = CharSet.Unicode)] public extern static bool setTextContents(Int32 vmID,< b > IntPtr accessibleContext < / b > ,string text); < / pre > We are using the Java Access Bridge (windows access bridge DLL) in trying to send text to a java window’s fields. We have initialized the A.P.I., successfully detected a java window (this only works correctly on the second call to the "isJavaWindow" function). We are able to obtain the accessible context via "getAccessibleContextFromHWND". We then use the context to recurse through the children until we find the text box in question. We are able to use "getTextInfo" function to read the contents of the field and the "getAccessibleContextInfo" function is returning good data. I can see that the property of the field is editable via the accessibleContextInfo data structure, however the "setTextContents" function always returns false. Here is the code snippet usage in C# (we have also tried using Autoit) A.P.I. version 2.0.2public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // enumerate the windows JavaAPIFunc.Windows_run(); bool found = false; Int32 VmId = 0; AccessibleContext Ac = new AccessibleContext(); AccessibleContextInfo Info = new AccessibleContextInfo(); foreach (KeyValuePair<intptr,> lWindow in OpenWindowGetter.GetOpenWindows()) { IntPtr lHandle = lWindow.Key; string lTitle = lWindow.Value; if (JavaAPIFunc.isJavaWindow((HWND)lHandle)) { MessageBox.Show("Found a java window"); JavaAPIFunc.getAccessibleContextFromHWND(lHandle, out VmId, out Ac); found = true; break; } } if(found) { TraverseTheBullshitInterface(VmId, Ac); } } private AccessibleContext TraverseTheBullshitInterface(Int32 VmId ,AccessibleContext AccessContext) { AccessibleContextInfo Info = new AccessibleContextInfo(); AccessibleTextItemsInfo TextInfo = new AccessibleTextItemsInfo(); JavaAPIFunc.getAccessibleContextInfo(VmId, AccessContext, ref Info); if (Info.name == "User name:" && Info.role_en_US == "text") { JavaAPIFunc.getAccessibleTextItems(VmId, AccessContext, ref TextInfo, 0); if(!JavaAPIFunc.setTextContents(VmId, AccessContext, "test")) { throw new Exception("Error setting text"); } } for (int i = 0; i < Info.childrenCount; ++i) { TraverseTheBullshitInterface(VmId,JavaAPIFunc.getAccessibleChildFromContext(VmId, AccessContext, i)); } return AccessContext; } }data structures:<pre lang="cs">public enum WABAPI { MAX_STRING_SIZE = 1024, SHORT_STRING_SIZE = 256, MAX_BUFFER_SIZE = 10240 }[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]public struct AccessibleContextInfo{[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.MAX_STRING_SIZE)]public string name; // the AccessibleName of the object[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.MAX_STRING_SIZE)]public string description; // the AccessibleDescription of the object[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]public string role; // localized AccesibleRole string[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]public string role_en_US; // AccesibleRole string in the en_US locale[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]public string states; // localized AccesibleStateSet string (comma separated)[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]public string states_en_US; // AccesibleStateSet string in the en_US locale (comma separated)public Int32 indexInParent; // index of object in parentpublic Int32 childrenCount; // # of children, if anypublic Int32 x; // screen coords in pixelspublic Int32 y; // "public Int32 width; // pixel width of objectpublic Int32 height; // pixel height of objectpublic Boolean accessibleComponent; // flags for various additionalpublic Boolean accessibleAction; // Java Accessibility interfacespublic Boolean accessibleSelection; // FALSE if this object doesn'tpublic Boolean accessibleText; // implement the additional interface// in question// BOOL accessibleValue; // old BOOL indicating whether AccessibleValue is supportedpublic Boolean accessibleInterfaces; // new bitfield containing additional interface flags}[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]public struct AccessibleTextInfo{public Int32 charCount; // # of characters in this text objectpublic Int32 caretIndex; // index of caretpublic Int32 indexAtPoint;}[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]public struct AccessibleTextItemsInfo{[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]public String letter;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]public String word;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.MAX_STRING_SIZE)]public String sentence;}[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]public struct AccessibleTextAttributesInfo{public Boolean bold;public Boolean italic;public Boolean underline;public Boolean strikethrough;public Boolean superscript;public Boolean subscript;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]public String backgroundColor;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]public String foregroundColor;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.SHORT_STRING_SIZE)]public String fontFamily;public Int32 fontSize;public Int32 alignment;public Int32 bidiLevel;public Single firstLineIndent;public Single leftIndent;public Single rightIndent;public Single lineSpacing;public Single spaceAbove;public Single spaceBelow;[MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)WABAPI.MAX_STRING_SIZE)]public String fullAttributesString;}Prototype import: [return: MarshalAs(UnmanagedType.Bool)] [DllImport("WindowsAccessBridge-64.dll", CallingConvention = CallingConvention.Cdecl, ThrowOnUnmappableChar = true, CharSet = CharSet.Unicode)] public extern static bool setTextContents(Int32 vmID, AccessibleContext accessibleContext, string text); 解决方案 <pre lang="c#"> [return: MarshalAs(UnmanagedType.Bool)] [DllImport("WindowsAccessBridge-64.dll", CallingConvention = CallingConvention.Cdecl, ThrowOnUnmappableChar = true, CharSet = CharSet.Unicode)] public extern static bool setTextContents(Int32 vmID, AccessibleContext accessibleContext, string text);</pre>Should be:<pre lang="c#"> [return: MarshalAs(UnmanagedType.Bool)] [DllImport("WindowsAccessBridge-64.dll", CallingConvention = CallingConvention.Cdecl, ThrowOnUnmappableChar = true, CharSet = CharSet.Unicode)] public extern static bool setTextContents(Int32 vmID, <b>IntPtr accessibleContext</b>, string text);</pre> 这篇关于使用java访问桥功能,除了“setTextContents”之外,Everything似乎都能正常工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 00:34