log(lvl + 1, "initScreens: entry"); primaryScreen = 0; setMouseRobot(); if (null == globalRobot) { screens = new Screen[1]; } else { screens = new Screen[runTime.nMonitors]; screens[0] = new Screen(0, runTime.mainMonitor); screens[0].initScreen(); int nMonitor = 0; for (int i = 1; i < screens.length; i++) { screens[i] = new Screen(i, nMonitor); screens[i].initScreen(); nMonitor++; if (getNumberScreens() > 1) { log(lvl, "initScreens: multi monitor mouse check"); Location lnow = Mouse.at(); float mmd = Settings.MoveMouseDelay; Location lc = null, lcn = null; for (Screen s : screens) { lc = s.getCenter(); Mouse.move(lc); lcn = Mouse.at(); if (!lc.equals(lcn)) { log(lvl, "*** multimonitor click check: %s center: (%d, %d) --- NOT OK: (%d, %d)",
public String saveCapture(String name, Region reg) { ScreenImage simg; if (reg == null) { simg = userCapture("Capture for image " + name); } else { simg = capture(reg); } if (simg == null) { return null; } else { return simg.saveInBundle(name); } }
if (!setActiveCapturePrompt()) { return null; int count = 0; while (!isComplete) { this.wait(0.1f); if (count++ > waitForScreenshot) { break; for (int is = 0; is < Screen.getNumberScreens(); is++) { OverlayCapturePrompt ocp = Screen.getScreen(is).prompt; if (ocp == null) { continue; closePrompt(Screen.getScreen(is)); simg = ocp.getSelection(); if (simg != null) { Screen.getScreen(is).lastScreenImage = simg; Screen.getScreen(is).prompt = null; isComplete = true; resetActiveCapturePrompt(); return simg;
public ScreenUnion() { super(true); _bounds = new Rectangle(); for (int i = 0; i < Screen.getNumberScreens(); i++) { _bounds = _bounds.union(Screen.getBounds(i)); } x = _bounds.x; y = _bounds.y; w = _bounds.width; h = _bounds.height; }
private static Region usex(Object... args) { int len = args.length; int nScreen = -1; if (len == 0 || len > 1) { scr = new Screen(); return scr; } nScreen = getInteger(args[0], -1); if (nScreen > -1) { scr = new Screen(nScreen); } else { Object oReg = args[0]; if (oReg instanceof Region) { scr = (Region) oReg; } } return scr; } //</editor-fold>
/** * Returns primary screen, if outside of any screen or not contained in a non-Desktop Screen instance (e.g. remote screen)<br> * * @return the real screen, that contains the given point */ public Screen getMonitor() { Rectangle r; Screen scr = null; if (otherScreen == null) { for (int i = 0; i < Screen.getNumberScreens(); i++) { r = Screen.getScreen(i).getBounds(); if (r.contains(this.x, this.y)) { scr = Screen.getScreen(i); break; } } } else { Debug.error("Location: getMonitor: (%s, %s) not on real screen - using primary", x, y); scr = Screen.getPrimaryScreen(); } if (scr == null) { Debug.error("Location: getMonitor: (%s, %s) outside any screen - using primary", x, y); scr = Screen.getPrimaryScreen(); } return scr; }
void drawMessage(Graphics2D g2d) { if (promptMsg == null) { return; } g2d.setFont(fontMsg); g2d.setColor(new Color(1f, 1f, 1f, 1)); int sw = g2d.getFontMetrics().stringWidth(promptMsg); int sh = g2d.getFontMetrics().getMaxAscent(); Rectangle ubound = scrOCP.getBounds(); for (int i = 0; i < Screen.getNumberScreens(); i++) { if (!Screen.getScreen(i).hasPrompt()) { continue; } Rectangle bound = Screen.getBounds(i); int cx = bound.x + (bound.width - sw) / 2 - ubound.x; int cy = bound.y + (bound.height - sh) / 2 - ubound.y; g2d.drawString(promptMsg, cx, cy); } }
/** * Returns null, if outside of any screen and not contained in a non-Desktop Screen instance (e.g. remote screen)<br> * subsequent actions WILL crash if not tested for null return * * @return the screen, that contains the given point */ public IScreen getScreen() { Rectangle r; if (otherScreen != null) { return otherScreen; } for (int i = 0; i < Screen.getNumberScreens(); i++) { r = Screen.getScreen(i).getBounds(); if (r.contains(this.x, this.y)) { return Screen.getScreen(i); } } Debug.error("Location: outside any screen (%s, %s) - subsequent actions might not work as expected", x, y); return null; }
@Override public ScreenImage capture(Rectangle rect) { Debug.log(4, "ScreenUnion: capture: (%d,%d) %dx%d", rect.x, rect.y, rect.width, rect.height); Screen s = Screen.getPrimaryScreen(); // Location tl = new Location(rect.getLocation()); // for (Screen sx : Screen.screens) { // if (sx.contains(tl)) { // s = sx; // break; // } // } ScreenImage si = s.capture(rect); return si; }
@Override public String toString() { Rectangle r = getBounds(); String scrText = curID == -1 ? "Union" : "" + curID; return String.format("S(%s)[%d,%d %dx%d] E:%s, T:%.1f", scrText, (int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight(), getThrowException() ? "Y" : "N", getAutoWaitTimeout()); }
/** * create a ScreenImage with given coordinates on this screen. * * @param x x-coordinate of the region to be captured * @param y y-coordinate of the region to be captured * @param w width of the region to be captured * @param h height of the region to be captured * @return the image of the region */ @Override public ScreenImage capture(int x, int y, int w, int h) { Rectangle rect = newRegion(new Location(x, y), w, h).getRect(); return capture(rect); }
public static String popFile(String title) { popat(new Screen(0).getCenter()); JFrame anchor = popLocation(); SikulixFileChooser fc = new SikulixFileChooser(anchor); File ret = fc.show(title); fc = null; if (anchor != null) { anchor.dispose(); } if (ret == null) { return ""; } return ret.getAbsolutePath(); }
@Override public int close(App.AppEntry app) { if (app.pid > -1) { return closeApp(app.pid); } if (app.window.startsWith("!")) { String token = app.window.substring(1); if(!token.isEmpty()) { switchto(app.window.substring(1), 0); RunTime.pause(1); new Screen().type(Key.F4, Key.ALT); return 0; } else { app = getApp(app.pid, app.name); } } if (app != null) { if (app.pid > -1) { return closeApp(app.pid); } else { return closeApp(app.execName.replaceAll("\"", "")); } } else { return -1; } }
/** * create a ScreenImage with given region on this screen * * @param reg The Region to be captured * @return the image of the region */ @Override public ScreenImage capture(Region reg) { return capture(reg.getRect()); }
} else { promptMsg = null; if (scr_img_rect.height > Screen.getPrimaryScreen().getBounds().getHeight()) { scr_img_scale = Screen.getPrimaryScreen().getBounds().getHeight() / scr_img_rect.height; if (scr_img_rect.width > Screen.getPrimaryScreen().getBounds().getWidth()) { scr_img_scale = Math.min(Screen.getPrimaryScreen().getBounds().getWidth() / scr_img_rect.width, scr_img_scale);
@Override public int getIdFromPoint(int x, int y) { Rectangle sr = getBounds(); int _x = x + getBounds().x; int _y = y + getBounds().y; for (int i = 0; i < getNumberScreens(); i++) { if (Screen.getScreen(i).contains(new Location(_x, _y))) { Debug.log(3, "ScreenUnion: getIdFromPoint: " + "(%d, %d) as (%d, %d) in (%d, %d, %d, %d) on %d", x, y, _x, _y, sr.x, sr.y, sr.width, sr.height, i); return i; } } Debug.log(3, "ScreenUnion: getIdFromPoint: " + "(%d, %d) as (%d, %d) in (%d, %d, %d, %d) on ???", x, y, _x, _y, sr.x, sr.y, sr.width, sr.height); return 0; }
/** * only a short version of toString() * * @return like S(0) [0,0, 1440x900] */ @Override public String toStringShort() { Rectangle r = getBounds(); String scrText = curID == -1 ? "Union" : "" + curID; return String.format("S(%s)[%d,%d %dx%d]", scrText, (int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight()); }