/** Create and display the context menu */
    private void displayContextMenu() {
      ContextMenu menu = ScilabContextMenu.createContextMenu();
      ModifyAction modify = new ModifyAction(SwingScilabVariableBrowser.this);
      menu.add(modify.createMenuItem());

      DeleteAction delete = new DeleteAction(SwingScilabVariableBrowser.this);
      menu.add(delete.createMenuItem());

      ExportToCsvAction csvExport =
          new ExportToCsvAction(
              (SwingScilabTab) SwingScilabVariableBrowser.this, UiDataMessages.EXPORTCSV);
      menu.add(csvExport.createMenuItem(SwingScilabVariableBrowser.this, UiDataMessages.EXPORTCSV));

      Menu menuPlot = ScilabMenu.createMenu();
      menuPlot.setText(UiDataMessages.PLOTALL);
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "plot2d", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "Matplot", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "grayplot", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "Sgrayplot", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "champ", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "histplot", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "mesh", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "surf", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "hist3d", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "contour2d", false));
      menuPlot.add(
          PlotAction.createMenuItem(
              (SwingScilabTab) SwingScilabVariableBrowser.this, "pie", false));
      menu.add(menuPlot);

      menu.setVisible(true);

      ((SwingScilabContextMenu) menu.getAsSimpleContextMenu())
          .setLocation(
              MouseInfo.getPointerInfo().getLocation().x,
              MouseInfo.getPointerInfo().getLocation().y);
    }
Пример #2
0
 /** @param args */
 public static void main(String[] args) throws InterruptedException {
   // TODO Auto-generated method stub
   while (true) {
     Thread.sleep(100);
     System.out.println(
         "("
             + MouseInfo.getPointerInfo().getLocation().x
             + ", "
             + MouseInfo.getPointerInfo().getLocation().y
             + ")");
   }
 }
Пример #3
0
  /** Starts adding points to the mouseEvents list every 2 milliseconds */
  private void collect() {
    int same = 0; // The number of times that the mouse has been in same position.
    pause = false; // whether or not the mouse is currently idle
    while (record) {
      if (!pause) {
        // If the mouse is not currently idle, A new point is added to the "mouseEvents" List. point
        // has x and y coordinates
        mouseEvents.add(
            new SimpleMouseEvent(
                MouseInfo.getPointerInfo().getLocation().x,
                MouseInfo.getPointerInfo().getLocation().y,
                0));
      }
      // If the mouse is currently set as idle, but mouvement has been detected: that is, if the
      // current position is different than
      // where the mouse is when it was set as idle...
      if (pause
          && ((MouseInfo.getPointerInfo().getLocation().x) != mouseEvents.getLast().gx()
              || MouseInfo.getPointerInfo().getLocation().y != mouseEvents.getLast().gy())) {
        unpause();
      }

      // Detects if the current position of the mouse is the same as the last time it was checked.
      if (mouseEvents.size() > 5
          && (mouseEvents
              .getLast()
              .toString()
              .equals(mouseEvents.get(mouseEvents.size() - 2).toString()))) {
        // If position is the same, the "same" count is increased.
        same++;
        // Once the mouse has been in the same place for 10 cycles, it is said to be idle.
        if (same == 10) {
          pause = true;
          // The stopwatch will count how long the mouse has been idle for
          stopWatch.start();
          System.out.println("Pause");
        }
      } else {
        // If the mouse has moved since last cycle, then the number of times it has been in the same
        // position is set to 0.
        same = 0;
      }
      try {
        Thread.sleep(2); // Delay between cycles.
      } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
      }
      if (!record) {
        gui.log("Recording Stopped.");
        gui.refreshActionList();
      }
    }
  }
Пример #4
0
  @Override
  public void mouseClicked(MouseEvent e) {
    // TODO Auto-generated method stub
    System.out.println(e);
    int mouseX = (int) MouseInfo.getPointerInfo().getLocation().getX();
    int mouseY = (int) MouseInfo.getPointerInfo().getLocation().getY();

    System.out.println("X" + mouseX);
    System.out.println("Y" + mouseY);

    if (mouseX > 185 && mouseX < 220 && mouseY > 510 && mouseY < 570) {
      System.out.println("Pootis-Bird");
      media.playMusicOnComputer("/Users/league/Desktop/pootis.wav");
    }
  }
Пример #5
0
 @Override
 public void buttonPress() {
   Mists.logger.log(Level.INFO, "{0} was clicked", this.getName());
   if (player.getAvailableActions().get(actionName) == null) {
     Mists.logger.warning(
         "Action button "
             + this.getName()
             + " was tied to an Action the player doesn't have ("
             + actionName
             + ")");
     return;
   }
   if (player.getAvailableActions().get(actionName).isOnCooldown()) {
     Mists.logger.info(
         "Tried to activate " + actionName + " by ActionButton, but it was on cooldown");
     return;
   }
   if (quickCast) {
     // If we're quickcasting, just fire skill at current mouse position
     Point p = MouseInfo.getPointerInfo().getLocation();
     double mouseX = p.getX() - Mists.primaryStage.getX();
     double mouseY = p.getY() - Mists.primaryStage.getY();
     // Mists.logger.info("Using action "+actionName+" towards
     // "+mouseX+player.getLocation().getLastxOffset()+"x"+
     // mouseY+player.getLocation().getLastyOffset());
     player.useAction(
         actionName,
         mouseX + player.getLocation().getLastxOffset(),
         mouseY + player.getLocation().getLastyOffset());
   } else {
     // If we're not quickcasting, the skill target needs to be verified with mouse click
     if (Mists.MistsGame.currentState instanceof LocationState)
       ((LocationState) Mists.MistsGame.currentState).castWithMouse(actionName);
   }
 }
Пример #6
0
  public void mouseEntered() {
    try {
      loadedMutex.acquire();
      if (rootCrowdLoaded) {
        Point mousePosition = new Point(MouseInfo.getPointerInfo().getLocation());
        SwingUtilities.convertPointFromScreen(mousePosition, this);

        for (int i = 0; i < rootCrowd.getMouseActionList().size(); i++) {
          // if the mouse click is in the hitbox then peform the action
          if (rootCrowd.getMouseActionList().get(i).isActive()
              && rootCrowd
                  .getMouseActionList()
                  .get(i)
                  .isInBounds(mousePosition.x, mousePosition.y)) {
            rootCrowd.getMouseActionList().get(i).mI(mousePosition);
          } else if (rootCrowd.getMouseActionList().get(i).isActive()
              && !rootCrowd
                  .getMouseActionList()
                  .get(i)
                  .isInBounds(mousePosition.x, mousePosition.y)) {
            rootCrowd.getMouseActionList().get(i).mO(mousePosition);
          }
        }
      }
      loadedMutex.release();
    } catch (InterruptedException ie) {
      System.err.println("interrupedMouseEnter");
      Thread.currentThread().interrupt();
    }
  }
Пример #7
0
 @Override
 public void mouseClicked(MouseEvent mouseEvent) {
   Board b = bgui.getGridView();
   if (b.getAction() == Board.Action.ADD && bgui.getSelectedComponent().equals("Gizmo")) {
     String gizmoShape = bgui.getGizmoShape();
     Point mouseP = MouseInfo.getPointerInfo().getLocation();
     Point gridP = b.getLocationOnScreen();
     int x = mouseP.x - gridP.x;
     int y = mouseP.y - gridP.y;
     boolean added = false;
     switch (gizmoShape) {
       case "Circle":
         added = m.addCircularBumper(x, y, 0, "circle");
         break;
       case "Triangle":
         added = m.addTriangularBumper(x, y, 0, "triangle");
         break;
       case "Square":
         added = m.addSquareBumper(x, y, 0, "square");
         break;
       case "Teleporter":
         added = m.addTeleporterBumper(x, y, 0, "teleporter");
         break;
       default:
     }
     if (added) {
       bgui.setMessageColor(Color.GREEN);
       bgui.setMessage(gizmoShape + " added!");
     } else {
       bgui.setMessageColor(Color.RED);
       bgui.setMessage("That space is occupied, " + gizmoShape + " cannot be added");
     }
   }
 }
Пример #8
0
  public static void requestFocus(Project project, final boolean useRobot) {
    JFrame frame = WindowManager.getInstance().getFrame(project);

    // the only reliable way I found to bring it to the top
    boolean aot = frame.isAlwaysOnTop();
    frame.setAlwaysOnTop(true);
    frame.setAlwaysOnTop(aot);

    int frameState = frame.getExtendedState();
    if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) {
      // restore the frame if it is minimized
      frame.setExtendedState(frameState ^ Frame.ICONIFIED);
    }
    frame.toFront();
    frame.requestFocus();
    if (useRobot && runningOnWindows7()) {
      try {
        // remember the last location of mouse
        final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation();

        // simulate a mouse click on title bar of window
        Robot robot = new Robot();
        robot.mouseMove(frame.getX(), frame.getY());
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

        // move mouse to old location
        robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY());
      } catch (Exception ex) {
        // just ignore exception, or you can handle it as you want
      } finally {
        frame.setAlwaysOnTop(false);
      }
    }
  }
Пример #9
0
  private void keepComputerAwake() {

    int toMoveX = (int) (Math.random() * 100);
    int toMoveY = (int) (Math.random() * 100);

    Point newMouse = MouseInfo.getPointerInfo().getLocation();

    if (newMouse.x != mouseX || newMouse.y != mouseY) {
      mouseX = newMouse.x;
      mouseY = newMouse.y;
      return;
    }

    if (robot == null) {
      try {
        robot = new Robot();
      } catch (AWTException e) {
        e.printStackTrace();
      }
    }

    robot.mouseMove(toMoveX, toMoveY);

    mouseX = toMoveX;
    mouseY = toMoveY;
  }
Пример #10
0
 // gravity at expects doubles to be formatted with origin at center of screen not at top-left
 public OrderedPairDouble gravityAt(OrderedPairDouble position) {
   // double commonScalar = 1;
   Point p = MouseInfo.getPointerInfo().getLocation();
   double gravity_x = (p.x - (this.longitude / 2));
   double gravity_y = (p.y - (this.latitude / 2));
   return new OrderedPairDouble(gravity_x, gravity_y);
 }
Пример #11
0
  public void mouseReleased(MouseEvent e) {

    Point mousePosition = new Point(MouseInfo.getPointerInfo().getLocation());
    SwingUtilities.convertPointFromScreen(mousePosition, this);

    // Mouse 1
    if (e.getButton() == MouseEvent.BUTTON1) {
      L_MOUSE_DOWN = false;
      for (int i = 0; i < rootCrowd.getMouseActionList().size(); i++) {
        // if the mouse click is in the hitbox then peform the action
        if (rootCrowd.getMouseActionList().get(i).isActive()
            && rootCrowd.getMouseActionList().get(i).isInBounds(mousePosition.x, mousePosition.y)) {
          if (rootCrowd.getMouseActionList().get(i).mU(mousePosition, e)) return;
        }
      }
    }
    // Mouse 2, BUTTON2 is middle mouse
    else if (e.getButton() == MouseEvent.BUTTON3) {
      for (int i = 0; i < rootCrowd.getMouseActionList().size(); i++) {
        // if the mouse click is in the hitbox then peform the action
        if (rootCrowd.getMouseActionList().get(i).isActive()
            && rootCrowd.getMouseActionList().get(i).isInBounds(mousePosition.x, mousePosition.y)) {
          if (rootCrowd.getMouseActionList().get(i).rMU(mousePosition, e)) return;
        }
      }
    }
  }
Пример #12
0
  /**
   * ****************************************************************************************************
   */
  public void enableAutoScanTimer() {
    if (autoAutoScan && (autoScanActivationTimer == null || !autoScanActivationTimer.isRunning())) {
      Point p = MouseInfo.getPointerInfo().getLocation();
      cursorPosX = p.x;
      cursorPosY = p.y;
      tickCountTime = System.currentTimeMillis();
      autoScanActivationTimer =
          new Timer(
              SCAN_ACTIVATION_CHECK_SPAN,
              new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                  if (!isScanning) {
                    Point p = MouseInfo.getPointerInfo().getLocation();
                    int x = p.x;
                    int y = p.y;
                    if ((x != cursorPosX) || (y != cursorPosY)) {
                      cursorPosX = x;
                      cursorPosY = y;
                      tickCountTime = System.currentTimeMillis();
                    } else if (System.currentTimeMillis() - tickCountTime > SCAN_ACTIVATION_DELAY) {
                      enableAutoScan();
                    }
                  }
                }
              });
      autoScanActivationTimer.start();
    }
  }
Пример #13
0
    private static Point fixPopupLocation(final Component contents, final int x, final int y) {
      if (!(contents instanceof JToolTip)) return new Point(x, y);

      final PointerInfo info;
      try {
        info = MouseInfo.getPointerInfo();
      } catch (InternalError e) {
        // http://www.jetbrains.net/jira/browse/IDEADEV-21390
        // may happen under Mac OSX 10.5
        return new Point(x, y);
      }
      int deltaY = 0;

      if (info != null) {
        final Point mouse = info.getLocation();
        deltaY = mouse.y - y;
      }

      final Dimension size = contents.getPreferredSize();
      final Rectangle rec = new Rectangle(new Point(x, y), size);
      ScreenUtil.moveRectangleToFitTheScreen(rec);

      if (rec.y < y) {
        rec.y += deltaY;
      }

      return rec.getLocation();
    }
Пример #14
0
 /** Unpauses the collection of mouse points */
 public void unpause() {
   if (pause) {
     System.out.println("unpause");
     stopWatch.stop();
     // Adds a mouse event that includes the new mouse locaiton and also the number of miliseconds
     // that the collection has been paused.
     mouseEvents.add(
         new SimpleMouseEvent(
             MouseInfo.getPointerInfo().getLocation().x,
             MouseInfo.getPointerInfo().getLocation().y,
             (int) stopWatch.getTime()));
     System.out.println(mouseEvents.getLast().toString());
     stopWatch.reset();
     pause = false;
   }
 }
Пример #15
0
 /**
  * Method that is called when a mouse button has been release. Used to add a mouse click action to
  * the list of events. -2 for left mouse up and -4 for right mouse up.
  *
  * @param button The mouse Button that was pressed.
  */
 public void mouseUp(int button) { // -2 for left mouse up, -4 for right mouse up
   if (record) {
     unpause(); // Ensures that the collection is not paused.
     if (button == 1) {
       mouseEvents.add(
           new SimpleMouseEvent(
               MouseInfo.getPointerInfo().getLocation().x,
               MouseInfo.getPointerInfo().getLocation().y,
               -2));
     } else if (button == 2) {
       mouseEvents.add(
           new SimpleMouseEvent(
               MouseInfo.getPointerInfo().getLocation().x,
               MouseInfo.getPointerInfo().getLocation().y,
               -4));
     }
     // System.out.println("Added: " + mouseEvents.getLast().toString());
   }
 }
Пример #16
0
 /**
  * Method that is called when a mouse button has been pressed. Used to add a mouse click action to
  * the list of events. -1 for leftmouse and -3 for right mouse
  *
  * @param button The mouse button that was pressed.
  */
 public void mouseDown(int button) { // -1 for leftmouseDown, -3 for right mouse down
   if (record) {
     unpause(); // ensures that the collection is not paused
     // Adds the appropriate action to the action list
     if (button == 1) {
       mouseEvents.add(
           new SimpleMouseEvent(
               MouseInfo.getPointerInfo().getLocation().x,
               MouseInfo.getPointerInfo().getLocation().y,
               -1));
     } else if (button == 2) {
       mouseEvents.add(
           new SimpleMouseEvent(
               MouseInfo.getPointerInfo().getLocation().x,
               MouseInfo.getPointerInfo().getLocation().y,
               -3));
     }
     // System.out.println("Added: " + mouseEvents.getLast().toString());
   }
 }
Пример #17
0
  @Override
  protected void paintChildren(Graphics g) {

    autoscale();

    super.paintChildren(g);
    if (IGV.getInstance().isRulerEnabled()) {
      int start = MouseInfo.getPointerInfo().getLocation().x - getLocationOnScreen().x;
      g.setColor(Color.BLACK);
      g.drawLine(start, 0, start, getHeight());
    }
  }
  public static void main(String[] args) throws Exception {
    Robot bot = new Robot();

    while (true) {
      int xc = (int) MouseInfo.getPointerInfo().getLocation().getX();
      int yc = (int) MouseInfo.getPointerInfo().getLocation().getY();
      Color pixelColor = bot.getPixelColor(xc, yc);

      System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
      System.out.flush();

      System.out.println("MouseX: " + xc);
      System.out.println("MouseY: " + yc);
      System.out.println(
          "R: "
              + pixelColor.getRed()
              + " G: "
              + pixelColor.getGreen()
              + " B: "
              + pixelColor.getBlue());
    }
  }
Пример #19
0
 @Override
 public void dragGestureRecognized(DragGestureEvent dge) {
   Cursor cursor = null;
   BufferedImage bi = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
   paint(bi.getGraphics());
   ImageMover.start(bi, MouseInfo.getPointerInfo().getLocation());
   String s = "[ANDITEM]";
   if (dge.getDragAction() == DnDConstants.ACTION_COPY) {
     cursor = DragSource.DefaultCopyDrop;
   }
   dge.startDrag(
       cursor, new SimpleDragObject.TransferableSimpleDragObject(new SimpleDragObject(s)));
 }
 @Override
 public void mouseClicked(MouseEvent mouseEvent) {
   Board b = bgui.getGridView();
   if (b.getAction() == Board.Action.KEY_DISCONNECT) {
     Point mouseP = MouseInfo.getPointerInfo().getLocation();
     Point gridP = b.getLocationOnScreen();
     int x = mouseP.x - gridP.x;
     int y = mouseP.y - gridP.y;
     x -= x % 20;
     y -= y % 20;
     f = m.findFlipper(x, y);
     String keys = "";
     if (f != null) {
       for (KeyConnectionFlipper kcf : m.getKeyConnectionsFlipper()) {
         if (kcf.getFlipper().equals(f)) {
           keys += ("'" + KeyEvent.getKeyText(kcf.getKeyID()) + "', ");
         }
       }
       if (keys.length() > 2) {
         keys = keys.substring(0, keys.length() - 2);
       }
       abs = null;
       b.requestFocus();
       bgui.setMessageColor(Color.BLACK);
       bgui.setMessage(
           "This flipper is connected to keys "
               + keys
               + ". Press key to remove connection to it.");
     } else if (m.getAbsorber() != null
         && x <= m.getAbsorber().getXBottomRight()
         && x >= m.getAbsorber().getXTopLeft()
         && y <= m.getAbsorber().getYBottomRight()
         && y >= m.getAbsorber().getYTopLeft()) {
       for (KeyConnectionAbs kca : m.getKeyConnectionsAbs()) {
         keys += ("'" + KeyEvent.getKeyText(kca.getKeyID()) + "', ");
       }
       if (keys.length() > 2) {
         keys = keys.substring(0, keys.length() - 2);
       }
       abs = m.getAbsorber();
       b.requestFocus();
       bgui.setMessageColor(Color.BLACK);
       bgui.setMessage(
           "This absorber is connected to keys "
               + keys
               + ". Press key to remove connection to it.");
     }
   }
 }
Пример #21
0
  @SuppressWarnings("NestedAssignment")
  public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    int steps = 3;

    while (true) {
      Point p = MouseInfo.getPointerInfo().getLocation();

      move(robot, p.x += steps, p.y);

      // update the pointer location, else you block the user's movement
      // (the pointer would move to the initial location instead of following the user's movement)
      p = MouseInfo.getPointerInfo().getLocation();
      move(robot, p.x, p.y += steps);

      p = MouseInfo.getPointerInfo().getLocation();
      move(robot, p.x -= steps, p.y);

      p = MouseInfo.getPointerInfo().getLocation();
      move(robot, p.x, p.y -= steps);

      LockSupport.parkNanos(TimeUnit.MINUTES.toNanos(2));
    }
  }
Пример #22
0
  /**
   * ****************************************************************************************************
   */
  public void disableScanning() {
    if (withSwaying) {
      stopSwayingTimer();
    }
    stopScanning();

    stopScanTimer();
    Toolkit.getDefaultToolkit().removeAWTEventListener(autoScanMouseListener);
    Toolkit.getDefaultToolkit().removeAWTEventListener(mouseDirectedScanListener);
    Toolkit.getDefaultToolkit().removeAWTEventListener(directedScanKeyboardListener);
    if (autoAutoScan) {
      Point p = MouseInfo.getPointerInfo().getLocation();
      cursorPosX = p.x;
      cursorPosY = p.y;
      tickCountTime = System.currentTimeMillis();
    }
  }
 protected static void processMagnification(IdeFrame frame, double magnification) {
   Point mouse = MouseInfo.getPointerInfo().getLocation();
   SwingUtilities.convertPointFromScreen(mouse, frame.getComponent());
   Component componentAt =
       SwingUtilities.getDeepestComponentAt(frame.getComponent(), mouse.x, mouse.y);
   if (componentAt != null) {
     Editor editor =
         PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext(componentAt));
     if (editor != null) {
       double currentSize = editor.getColorsScheme().getEditorFontSize();
       int defaultFontSize =
           EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
       ((EditorEx) editor)
           .setFontSize((int) (Math.max(currentSize + magnification * 3, defaultFontSize)));
     }
   }
 }
Пример #24
0
  @Override
  public void mouseClicked(MouseEvent e) {

    indexOfLabelPressed = -1;

    for (int i = 0; i < orderLabel.length; i++) {
      if (e.getSource() == orderLabel[i]) {
        indexOfLabelPressed = i;
        PointerInfo a = MouseInfo.getPointerInfo();
        Point b = a.getLocation();
        int x = (int) b.getX();
        int y = (int) b.getY();
        popup.setLocation(x, y);
        popup.setInvoker(popup);
        popup.setVisible(true);
        revalidate();
        repaint();
      }
    }

    if (e.getSource() == topPanelLabel) {
      indexOfLabelPressed = -2;
    }

    if (indexOfLabelPressed == -1) {
      okDiscountButton.setText("Deduct");
      discountPopup.setLocation(700, 220);
      discountPopup.setInvoker(discountPopup);
      discountPopup.setVisible(true);
      itemDiscountPopupLabel.setText(
          "$"
              + finalModifier
              + " off with "
              + menuPanel.df.format((1 - finalPercentModifier) * 100)
              + "%"
              + " discount");
    } else if (indexOfLabelPressed == -2) {
      // TODO
      resetAll();
    }
  }
Пример #25
0
 private void checkMousePosition(Location p) {
   PointerInfo mp = MouseInfo.getPointerInfo();
   Point pc;
   if (mp == null) {
     Debug.error(
         "RobotDesktop: checkMousePosition: MouseInfo.getPointerInfo invalid\nafter move to %s",
         p);
   } else {
     pc = mp.getLocation();
     if (pc.x != p.x || pc.y != p.y) {
       Debug.error(
           "RobotDesktop: checkMousePosition: should be %s\nbut after move is %s"
               + "\nPossible cause: Mouse actions are blocked generally or by the frontmost application."
               + (Settings.isWindows()
                   ? "\nYou might try to run the SikuliX stuff as admin."
                   : ""),
           p,
           new Location(pc));
     }
   }
 }
Пример #26
0
  /**
   * ****************************************************************************************************
   */
  public void startSwayingTimer() {
    if (swayingTimer == null) {
      swayingTimer =
          new Timer(
              SWAYING_SPAN,
              new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                  changeSwayingPos();
                }
              });
      swayingCounter = 0;
      Point p = MouseInfo.getPointerInfo().getLocation();
      swayingCursorX = p.x;
      swayingCursorY = p.y;
      swayingTimer.start();
    }

    if (!swayingTimer.isRunning()) {
      swayingTimer.start();
    }
  }
  public static void main(String[] args) throws Exception {
    DatagramSocket serverSocket = new DatagramSocket(8083);
    int count = 0;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int middleOfScreenX = (int) Math.round(screenSize.getWidth() / 2);
    int middleOfScreenY = (int) Math.round(screenSize.getHeight() / 2);

    System.out.println("Server started");
    byte[] receiveData = new byte[128];
    Robot robot = new Robot();
    while (true) {
      DatagramPacket receivedPacket = new DatagramPacket(receiveData, receiveData.length);
      serverSocket.receive(receivedPacket);

      SenderObject senderObject = SenderObject.parseFrom(receivedPacket.getData());
      float y = senderObject.getY();
      float x = senderObject.getX();
      int type = senderObject.getType();
      System.out.println(senderObject.toString());
      // Get the current pointer location.
      Point mousePointer = MouseInfo.getPointerInfo().getLocation();

      // Check if the type is mouse click.
      if (type == 2) {
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
      }
      // otherwise move the mouse pointer by subtracting to current
      // coordinates. Subtraction, because of the flipped right and left.
      else {
        float curX = mousePointer.x - x;
        float curY = mousePointer.y - y;
        robot.mouseMove(Math.round(curX), Math.round(curY));
      }
    }
  }
Пример #28
0
 public Object run() throws HeadlessException {
   return MouseInfo.getPointerInfo().getLocation();
 }
Пример #29
0
  public void init() {
    try {
      robot = new Robot();
    } catch (AWTException ex) {
      ex.printStackTrace();
      throw new RuntimeException(ex);
    }
    this.setLayout(new BorderLayout());

    target.setBackground(Color.green);
    target.setName("GreenBox"); // for the ease of debug
    target.setPreferredSize(new Dimension(100, 100));
    String toolkit = Toolkit.getDefaultToolkit().getClass().getName();

    // on X systems two buttons are reserved for wheel though they are countable by MouseInfo.
    int buttonsNumber =
        toolkit.equals("sun.awt.windows.WToolkit")
            ? MouseInfo.getNumberOfButtons()
            : MouseInfo.getNumberOfButtons() - 2;

    for (int i = 0; i < 8; i++) {
      buttonNumber.add("BUTTON" + (i + 1) + "_MASK");
    }

    pressOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now pressing : " + (buttonNumber.getSelectedIndex() + 1));

            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mousePress(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });

    releaseOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now releasing : " + (buttonNumber.getSelectedIndex() + 1));
            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mouseRelease(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });

    clickOn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Now clicking : " + (buttonNumber.getSelectedIndex() + 1));
            Timer timer = new Timer();
            TimerTask robotInteraction =
                new TimerTask() {
                  public void run() {
                    robot.mouseMove(updateTargetLocation().x, updateTargetLocation().y);
                    robot.mousePress(getMask(buttonNumber.getSelectedIndex() + 1));
                    robot.mouseRelease(getMask(buttonNumber.getSelectedIndex() + 1));
                  }
                };
            timer.schedule(robotInteraction, SEND_DELAY);
          }
        });
    target.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            Sysout.println("" + e);
          }

          public void mouseReleased(MouseEvent e) {
            Sysout.println("" + e);
          }

          public void mouseClicked(MouseEvent e) {
            Sysout.println("" + e);
          }
        });

    String[] instructions = {
      "Do provide an instruction to the robot by",
      "choosing the button number to act and ",
      "pressing appropriate java.awt.Button on the left.",
      "Inspect an output in the TextArea below.",
      "Please don't generate non-natural sequences like Release-Release, etc.",
      "If you use keyboard be sure that you released the keyboard shortly.",
      "If events are generated well press Pass, otherwise Fail."
    };
    Sysout.createDialogWithInstructions(instructions);
  } // End  init()
Пример #30
0
 public static int getNumberOfMouseButtons() {
   return MouseInfo.getNumberOfButtons();
 }