private bool enableJavaUiNode(UiNode node) { if (node.WindowHandle != IntPtr.Zero && node.ProcessName == "javaw.exe" && !JavaUiNode.accessBridge.Functions.IsJavaWindow(node.WindowHandle)) { StopHighlight(); //提示用户是否启用JAVA自动化 var ret = System.Windows.MessageBox.Show("是否启用Java Access Bridge?", "询问", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question, System.Windows.MessageBoxResult.Yes); if (ret == System.Windows.MessageBoxResult.Yes) { //java8及以后的版本直接调用命令行,之前的版本需要手动安装 var jabswitchExe = System.IO.Path.GetDirectoryName(node.ProcessFullPath) + @"\jabswitch.exe"; if (System.IO.File.Exists(jabswitchExe)) { //存在jabswitch.exe,则可直接调用jabswitch.exe -enable来启用 UiCommon.RunProcess(jabswitchExe, "-enable", true); } else { //需要主动安装accessbridge相关文件(根据32位或64位的JRE进行拷贝) var javaExe = System.IO.Path.GetDirectoryName(node.ProcessFullPath) + @"\java.exe"; string windowsHome = Environment.GetFolderPath(Environment.SpecialFolder.Windows); string javaHome = System.IO.Directory.GetParent(System.IO.Path.GetDirectoryName(node.ProcessFullPath)).FullName; installJavaAccessBridge(Environment.Is64BitOperatingSystem, UiCommon.IsExe64Bit(javaExe), windowsHome, javaHome); } System.Windows.MessageBox.Show("操作完成,请重新运行Java程序以便操作生效", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information); } return(true); } return(false); }
public void SetForeground() { //此处其实不会走进来,因为JAVA元素的直接父窗口为UIAUiNode if (WindowHandle != IntPtr.Zero) { UiCommon.SetForegroundWindow(WindowHandle); } }
private void keyStateDispatcherTimer_Tick(object sender, EventArgs e) { const int MBUTTON = 0x04; if (UiCommon.GetAsyncKeyState(MBUTTON) != 0) { doDelaySelect(); } }
public void SetForeground() { var directWindow = DirectTopLevelWindow; if (directWindow != null) { UiCommon.ForceShow(directWindow.WindowHandle); DirectTopLevelWindow.uiNode.SetForeground(); } }
public OverlayForm() { InitializeComponent(); this.panelBorderLeft = createPanel(Color.FromArgb(232, 193, 116)); this.panelBorderTop = createPanel(Color.FromArgb(232, 193, 116)); this.panelBorderRight = createPanel(Color.FromArgb(232, 193, 116)); this.panelBorderBottom = createPanel(Color.FromArgb(232, 193, 116)); this.panelInside = createPanel(Color.FromArgb(123, 159, 212)); this.Cursor = UiCommon.GetCursor(Properties.Resources.cursor); }
private void installJavaAccessBridge(bool isOperatingSystem64Bit, bool isJava64Bit, string windowsHome, string javaHome) { var jabPath = System.Environment.CurrentDirectory + @"\JAB"; if (isOperatingSystem64Bit) { //Windows64位系统安装JAB UiCommon.CopyFileToDir(jabPath + @"\WindowsAccessBridge-64.dll", windowsHome + @"\SYSTEM32"); UiCommon.CopyFileToDir(jabPath + @"\WindowsAccessBridge-32.dll", windowsHome + @"\SYSWOW64"); if (isJava64Bit) { UiCommon.CopyFileToDir(jabPath + @"\JavaAccessBridge-64.dll", javaHome + @"\bin"); UiCommon.CopyFileToDir(jabPath + @"\JAWTAccessBridge-64.dll", javaHome + @"\bin"); UiCommon.CopyFileToDir(jabPath + @"\access-bridge-64.jar", javaHome + @"\lib\ext"); } else { UiCommon.CopyFileToDir(jabPath + @"\JavaAccessBridge-32.dll", javaHome + @"\bin"); UiCommon.CopyFileToDir(jabPath + @"\JAWTAccessBridge-32.dll", javaHome + @"\bin"); UiCommon.CopyFileToDir(jabPath + @"\access-bridge-32.jar", javaHome + @"\lib\ext"); } UiCommon.CopyFileToDir(jabPath + @"\accessibility.properties", javaHome + @"\lib"); UiCommon.CopyFileToDir(jabPath + @"\jaccess.jar", javaHome + @"\lib\ext"); } else { //Windows32位系统安装JAB UiCommon.CopyFileToDir(jabPath + @"\WindowsAccessBridge.dll", windowsHome + @"\SYSTEM32"); UiCommon.CopyFileToDir(jabPath + @"\JavaAccessBridge.dll", javaHome + @"\bin"); UiCommon.CopyFileToDir(jabPath + @"\JAWTAccessBridge.dll", javaHome + @"\bin"); UiCommon.CopyFileToDir(jabPath + @"\access-bridge.jar", javaHome + @"\lib\ext"); UiCommon.CopyFileToDir(jabPath + @"\accessibility.properties", javaHome + @"\lib"); UiCommon.CopyFileToDir(jabPath + @"\jaccess.jar", javaHome + @"\lib\ext"); } }
private void dispatcherTimer_Tick(object sender, EventArgs e) { try { enablePassThrough = true; var screenPoint = System.Windows.Forms.Cursor.Position; AutomationElement element = null; if (IsWindowHighlight) { IntPtr hWnd = UiCommon.GetRootWindow(screenPoint); if (hWnd != IntPtr.Zero) { element = UIAUiNode.UIAAutomation.FromHandle(hWnd); } } else { try { element = UIAUiNode.UIAAutomation.FromPoint(screenPoint); } catch (Exception) { if (element == null) { IntPtr hWnd = UiCommon.WindowFromPoint(screenPoint); if (hWnd != IntPtr.Zero) { element = UIAUiNode.UIAAutomation.FromHandle(hWnd); } } } if (inspectJavaUiNode(element, screenPoint)) { return; } } CurrentHighlightElement = new UIAUiNode(element); if (element == null) { return; } var rect = element.BoundingRectangle; //计算鼠标点击时的相对元素的偏移,以供后期有必要时使用 CurrentHighlightElementRelativeClickPos = new Point(screenPoint.X - rect.Left, screenPoint.Y - rect.Top); this.MoveRect(rect); } catch (Exception) { } finally { enablePassThrough = false; this.TopMost = true; } }
public UiNode FindRelativeNode(int position, int offsetX, int offsetY) { UIAUiNode relativeNode = null; Rectangle rect = automationElement.BoundingRectangle; int posX, posY; Point point; switch (position) { case 0: //中心位置偏移 posX = rect.Location.X + rect.Width / 2; posY = rect.Location.Y + rect.Height / 2; point = new Point(posX + offsetX, posY + offsetY); break; case 1: //左上角偏移 posX = rect.Location.X; posY = rect.Location.Y; point = new Point(posX + offsetX, posY + offsetY); break; case 2: //右上角偏移 posX = rect.Location.X + rect.Width; posY = rect.Location.Y; point = new Point(posX + offsetX, posY + offsetY); break; case 3: //左下角偏移 posX = rect.Location.X; posY = rect.Location.Y + rect.Height; point = new Point(posX + offsetX, posY + offsetY); break; case 4: //右下角偏移 posX = rect.Location.X + rect.Width; posY = rect.Location.Y + rect.Height; point = new Point(posX + offsetX, posY + offsetY); break; default: //默认中心偏移 posX = rect.Location.X + rect.Width / 2; posY = rect.Location.Y + rect.Height / 2; point = new Point(posX + offsetX, posY + offsetY); break; } try { this.automationElement = UIAUiNode.UIAAutomation.FromPoint(point); } catch (Exception) { if (this.automationElement == null) { IntPtr hWnd = UiCommon.WindowFromPoint(point); if (hWnd != IntPtr.Zero) { this.automationElement = UIAUiNode.UIAAutomation.FromHandle(hWnd); } } } relativeNode = new UIAUiNode(automationElement); return(relativeNode); }