/** * to block the device globally <br> * only the contained device methods without owner will be granted * * @return success */ public boolean block() { return block(null); }
protected synchronized boolean use(Object owner) { if (owner == null) { owner = this; } else if (isNotLocal(owner)) { return false; inUse = true; try { checkLastPos(); } catch (Exception ex) {} checkShouldRunCallback(); if (shouldTerminate) { shouldTerminate = false; log(lvl + 1, "%s: use start: %s", devName, owner); return true; log(-1, "synch problem - use start: %s", owner); return false;
protected synchronized boolean let(Object owner) { if (owner == null) { owner = this; } else if (isNotLocal(owner)) { return false; } if (inUse && this.owner == owner) { if (keep) { keep = false; return true; } if (isMouse) { lastPos = getLocation(); } inUse = false; this.owner = null; notify(); log(lvl + 1, "%s: use stop: %s", devName, owner); return true; } return false; }
protected synchronized boolean keep(Object ownerGiven) { if (ownerGiven == null) { ownerGiven = this; } else if (isNotLocal(ownerGiven)) { return false; } if (inUse && owner == ownerGiven) { keep = true; log(lvl + 1, "%s: use keep: %s", devName, ownerGiven); return true; } return false; }
/** * free the mouse globally for this owner after a block(owner) * * @param ownerGiven Object * @return success (false means: not blocked currently for this owner) */ public boolean unblock(Object ownerGiven) { if (ownerGiven == null) { ownerGiven = device; } else if (isNotLocal(ownerGiven)) { return false; } if (blocked && owner == ownerGiven) { blocked = false; let(ownerGiven); return true; } return false; }
return; Location pos = getLocation(); if (pos != null && (lastPos.x != pos.x || lastPos.y != pos.y)) { log(lvl, "%s: moved externally: now (%d,%d) was (%d,%d) (mouseMovedResponse %d)", devName, pos.x, pos.y, lastPos.x, lastPos.y, mouseMovedResponse); if (mouseMovedResponse > 0) { if (MouseMovedHighlight) { showMousePos(pos.getPoint()); delay(500); pos = getLocation(); if (MouseMovedHighlight) { showMousePos(pos.getPoint());
if (get().device.isSuspended() || loc.isOtherScreen()) { return null; get().device.use(); Device.delay(mouse.beforeWait); Settings.ClickDelay = mouse.innerWait / 1000; click(loc, mouse.buttons, 0, ((Mouse) get()).clickDouble, null); Device.delay(mouse.afterWait); get().device.let(); return loc;
protected static void wheel(int direction, int steps, Region region, int stepDelay) { if (get().device.isSuspended()) { return; } IRobot r = Screen.getRobot(region); get().device.use(region); Debug.log(3, "Region: wheel: %s steps: %d", (direction == WHEEL_UP ? "WHEEL_UP" : "WHEEL_DOWN"), steps); for (int i = 0; i < steps; i++) { r.mouseWheel(direction); r.delay(stepDelay); } get().device.let(region); } }
protected static void up(int buttons, Region region) { if (get().device.isSuspended()) { return; } Screen.getRobot(region).mouseUp(buttons); if (region != null) { get().device.let(region); } }
protected static void down(int buttons, Region region) { if (get().device.isSuspended()) { return; } get().device.use(region); Screen.getRobot(region).mouseDown(buttons); }
public static void reset() { if (mouse == null) { return; } get().device.unblock(get().device.owner); mouse.get().device.let(get().device.owner); get().device.let(get().device.owner); get().device.mouseMovedResponse = get().device.MouseMovedIgnore; get().device.mouseMovedCallback = null; get().device.callback = null; get().device.lastPos = null; Screen.getPrimaryScreen().getRobot().mouseReset(); }
protected boolean let() { return let(null); }
public static Location at() { return get().device.getLocation(); }
protected static boolean keep(Object owner) { return get().device.keep(owner); }
public static void init() { if (mouse == null) { log(3, "init start"); mouse = new Mouse(); mouse.device = new Device(mouse); mouse.device.isMouse = true; Location loc = at(); move(loc); mouse.device.lastPos = null; log(3, "init end"); } }
protected static int move(Location loc, Region region) { if (get().device.isSuspended()) { return 0; } if (loc != null) { IRobot r = null; IScreen s = loc.getScreen(); if (s == null) { return 0; } r = s.getRobot(); if (r == null) { return 0; } if (!r.isRemote()) { get().device.use(region); } r.smoothMove(loc); r.waitForIdle(); if (!r.isRemote()) { get().device.let(region); } return 1; } return 0; }
protected static boolean let() { return get().device.let(null); }
/** * check if mouse was moved since last mouse action * * @return true/false */ public static boolean hasMoved() { Location pos = get().device.getLocation(); if (get().device.lastPos.x != pos.x || get().device.lastPos.y != pos.y) { return true; } return false; }