public PlateGUIRobot() {
   try {
     robot = new Robot();
   } catch (AWTException e) {
     e.printStackTrace();
   }
 }
 private void checkChanges(ScreenImage img) {
   if (Settings.UseImageFinder) {
     if (_lastImageMat.empty()) {
       _lastImageMat = Image.createMat(img.getImage());
       return;
     }
     ImageFinder f = new ImageFinder(_lastImageMat);
     f.setMinChanges(_minChanges);
     org.opencv.core.Mat current = Image.createMat(img.getImage());
     if (f.hasChanges(current)) {
       // TODO implement ChangeObserver: processing changes
       Debug.log(3, "ChangeObserver: processing changes");
     }
     _lastImageMat = current;
   } else {
     if (_lastImgMat == null) {
       _lastImgMat = Image.convertBufferedImageToMat(img.getImage());
       return;
     }
     FindInput fin = new FindInput();
     fin.setSource(_lastImgMat);
     Mat target = Image.convertBufferedImageToMat(img.getImage());
     fin.setTarget(target);
     fin.setSimilarity(_minChanges);
     FindResults results = Vision.findChanges(fin);
     try {
       callChangeObserver(results);
     } catch (AWTException e) {
       Debug.error("EventMgr: checkChanges: ", e.getMessage());
     }
     _lastImgMat = target;
   }
 }
Beispiel #3
0
 private void startRobot() {
   try {
     robot = new Robot();
   } catch (AWTException e) {
     e.printStackTrace();
   }
 }
Beispiel #4
0
 public RobotBot() {
   try {
     this.robot = new Robot();
   } catch (AWTException e) {
     e.printStackTrace();
   }
 }
  /** @param model File upload in IE browser. */
  public void fileUploadinIE(MethodParameters model) {
    model.getElement().get(0).click();
    StringSelection ss = new StringSelection(model.getData());
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
    Robot r;
    try {
      r = new Robot();

      r.keyPress(KeyEvent.VK_ENTER);

      r.keyRelease(KeyEvent.VK_ENTER);

      r.keyPress(KeyEvent.VK_CONTROL);
      r.keyPress(KeyEvent.VK_V);
      r.keyRelease(KeyEvent.VK_V);
      r.keyRelease(KeyEvent.VK_CONTROL);

      r.keyPress(KeyEvent.VK_ENTER);
      r.keyRelease(KeyEvent.VK_ENTER);

    } catch (AWTException e) {

      MainTestNG.LOGGER.severe(e.getMessage());
    }
  }
 public RobotHandler() {
   try {
     robot = new Robot();
   } catch (AWTException e) {
     e.printStackTrace();
   }
 }
Beispiel #7
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;
  }
  public TestRemoveShowContract() {
    Show fakeShow = new Show();
    fakeShow.setName("My Show");
    mockShows.add(fakeShow);

    String fileName = TedSystemInfo.getUserDirectory() + "shows.ted";
    System.out.println("Shows.ted location: " + fileName);

    File showFile = new File(fileName);
    if (showFile.exists()) {
      System.out.println("Deleting shows.ted to ensure fresh start...");
      showFile.delete();
    }

    TedIO.getInstance().SaveShows(this.mockShows);

    junit.extensions.jfcunit.WindowMonitor.start();

    this.main = new TedMainDialogController(false, true);
    this.main.setViewVisible(true);

    try {
      setHelper(new RobotTestHelper());
    } catch (AWTException e) {
      fail("AWTException occurred, we can't go on! Message: " + e.getMessage());
    }
  }
  private void createShadowBorder() {
    backgroundImage =
        new BufferedImage(
            getWidth() + SHADOW_WIDTH, getHeight() + SHADOW_WIDTH, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) backgroundImage.getGraphics();

    try {
      Robot robot = new Robot(getGraphicsConfiguration().getDevice());
      BufferedImage capture =
          robot.createScreenCapture(
              new Rectangle(getX(), getY(), getWidth() + SHADOW_WIDTH, getHeight() + SHADOW_WIDTH));
      g2.drawImage(capture, null, 0, 0);
    } catch (AWTException e) {
      e.printStackTrace();
    }

    BufferedImage shadow =
        new BufferedImage(
            getWidth() + SHADOW_WIDTH, getHeight() + SHADOW_WIDTH, BufferedImage.TYPE_INT_ARGB);
    Graphics graphics = shadow.getGraphics();
    graphics.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f));
    graphics.fillRoundRect(6, 6, getWidth(), getHeight(), 12, 12);

    g2.drawImage(shadow, getBlurOp(7), 0, 0);
  }
Beispiel #10
0
  private MainPanel(final JFrame frame) {
    super();
    add(check);
    setPreferredSize(new Dimension(320, 240));

    if (!SystemTray.isSupported()) {
      frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      return;
    }
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowIconified(WindowEvent e) {
            if (check.isSelected()) {
              e.getWindow().dispose();
            }
          }
        });
    // or
    // frame.addWindowStateListener(new WindowStateListener() {
    //    @Override public void windowStateChanged(WindowEvent e) {
    //        if (check.isSelected() && e.getNewState() == Frame.ICONIFIED) {
    //            e.getWindow().dispose();
    //        }
    //    }
    // });

    final SystemTray tray = SystemTray.getSystemTray();
    Dimension d = tray.getTrayIconSize();
    BufferedImage image = makeBufferedImage(new StarIcon(), d.width, d.height);
    final PopupMenu popup = new PopupMenu();
    final TrayIcon icon = new TrayIcon(image, "TRAY", popup);

    MenuItem item1 = new MenuItem("OPEN");
    item1.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            frame.setVisible(true);
          }
        });
    MenuItem item2 = new MenuItem("EXIT");
    item2.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            tray.remove(icon);
            frame.dispose();
            // frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
          }
        });
    popup.add(item1);
    popup.add(item2);

    try {
      tray.add(icon);
    } catch (AWTException e) {
      e.printStackTrace();
    }
  }
Beispiel #11
0
  public static void captureScreen(Component Area) {

    // Find out where the user would like to save their screen shot
    String fileName = null;
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Screen Shots", "png");
    chooser.setFileFilter(filter);
    int returnVal = chooser.showSaveDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File saveFile = new File(chooser.getSelectedFile().getPath() + ".png");
      fileName = saveFile.toString();

      // Check to see if we will overwrite the file
      if (saveFile.exists()) {
        int overwrite =
            JOptionPane.showConfirmDialog(null, "File already exists, do you want to overwrite?");
        if (overwrite == JOptionPane.CANCEL_OPTION
            || overwrite == JOptionPane.CLOSED_OPTION
            || overwrite == JOptionPane.NO_OPTION) {
          return;
        }
      }
    }
    // If they didn't hit approve, return
    else {
      return;
    }

    // Determine the exact coordinates of the screen that is to be captured
    Dimension screenSize = Area.getSize();
    Rectangle screenRectangle = new Rectangle();
    screenRectangle.height = screenSize.height;
    screenRectangle.width = screenSize.width;
    screenRectangle.x = Area.getLocationOnScreen().x;
    screenRectangle.y = Area.getLocationOnScreen().y;

    // Here we have to make the GUI Thread sleep for 1/4 of a second
    // just to give the save dialog enough time to close off of the
    // screen. On slower computers they were capturing the screen
    // before the dialog was out of the way.
    try {
      Thread.currentThread();
      Thread.sleep(250);
    } catch (InterruptedException e1) {
      e1.printStackTrace();
    }

    // Attempt to capture the screen at the defined location.
    try {
      Robot robot = new Robot();
      BufferedImage image = robot.createScreenCapture(screenRectangle);
      ImageIO.write(image, "png", new File(fileName));
    } catch (AWTException e) {
      e.printStackTrace();
    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, "Could not save screen shoot at: " + fileName);
      e.printStackTrace();
    }
  }
Beispiel #12
0
 public ScreenshotMaker() {
   try {
     robot = new Robot();
   } catch (AWTException e) {
     e.printStackTrace();
   }
   rectangle = new Rectangle(0, 0, 1000, 800);
 }
 // Set if the application is in editing mode based on the state of the shift key
 public void setEditingMode() {
   try {
     Robot robot = new Robot();
     robot.keyRelease(KeyEvent.VK_SHIFT);
   } catch (AWTException e) {
     e.printStackTrace();
   }
 }
Beispiel #14
0
 public Tests(Wiimote wim) {
   wiimote = wim;
   wiimote.addWiiMoteEventListeners(this);
   try {
     robot = new Robot();
   } catch (AWTException e) {
     e.printStackTrace();
   }
 }
 /** 按Esc键的封装方法 */
 public static void pressEscKey() {
   Robot robot = null;
   try {
     robot = new Robot();
   } catch (AWTException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   robot.keyPress(KeyEvent.VK_ESCAPE);
   robot.keyRelease(KeyEvent.VK_ESCAPE);
 }
Beispiel #16
0
  /**
   * Creates an instance of <tt>TransparentBackground</tt> by specifying the parent <tt>Window</tt>
   * - this is the window that should be made transparent.
   *
   * @param window The parent <tt>Window</tt>
   */
  public TransparentBackground(Window window) {
    this.window = window;

    Robot rbt;
    try {
      rbt = new Robot();
    } catch (AWTException e) {
      e.printStackTrace();
      rbt = null;
    }
    this.robot = rbt;
  }
 public static void main(String... args) {
   RobotHero robot = new RobotHero();
   try {
     robot.run();
   } catch (InterruptedException e) {
     System.out.println("Excecution interrupted - exiting");
   } catch (AWTException e) {
     // This exception can only really happen as a result
     // of trying to run this CLI in a very non-standard way
     e.printStackTrace();
   }
 }
Beispiel #18
0
  protected void setUp() throws Exception {
    StorageWrapper.deleteFromClient("cs320.patient");
    cont = DisplayController.GetInstance();

    cont.main(null);
    loginDisplay = (LoginDisplay) DisplayController.GetInstance().getCurrentDisplay();
    // DisplayController.main(null);
    try {
      ace = new HelpSR();
    } catch (AWTException e) {
      e.printStackTrace();
    }
  }
  public static void main(String s[]) {

    // Getting save directory
    String saveDir;
    if (s.length > 0) {
      saveDir = s[0];
    } else {
      saveDir =
          JOptionPane.showInputDialog(
              null,
              "Please enter directory where "
                  + "the images is/will be saved\n\n"
                  + "Also possible to specifiy as argument 1 when "
                  + "running this program.",
              "l:\\webcamtest");
    }

    String layout = "";
    if (s.length > 1) {
      layout = s[1];
    }

    // Move mouse to the point 5000,5000 px (out of the screen)
    Robot rob;
    try {
      rob = new Robot();
      rob.setAutoDelay(500); // 0,5 s
      rob.mouseMove(5000, 5000);
    } catch (AWTException e) {
      e.printStackTrace();
    }

    // Make the main window
    JFrame frame = new JFrame();
    frame.setAlwaysOnTop(true);
    frame.setTitle(
        "Webcam capture and imagefading - "
            + "Vitenfabrikken Jærmuseet - "
            + "made by Hallvard Nygård - "
            + "Vitenfabrikken.no / Jaermuseet.no");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setUndecorated(true);

    WebcamCaptureAndFadePanel panel = new WebcamCaptureAndFadePanel(saveDir, layout);
    frame.getContentPane().add(panel);
    frame.addKeyListener(panel);
    frame.pack();

    frame.setVisible(true);
  }
  @Override
  protected void initialize() {
    window.requestFocusInWindow();

    // Replace the default keyboard input with DyehardKeyboard
    window.removeKeyListener(keyboard);
    keyboard = new DyehardKeyboard();
    window.addKeyListener(keyboard);

    window.addMouseListener(mouse);

    resources.setClassInJar(this);

    state = State.BEGIN;
    GameState.TargetDistance = Configuration.worldMapLength;
    world = new GameWorld();

    // preload sound/music, and play bg music
    DyeHardSound.playBgMusic();

    hero = new Hero();

    // move mouse to where center of hero is
    try {
      Robot robot = new Robot();

      robot.mouseMove(
          window.getLocationOnScreen().x
              + (int) (hero.center.getX() * window.getWidth() / BaseCode.world.getWidth()),
          window.getLocationOnScreen().y
              + window.getHeight()
              - (int) (hero.center.getX() * window.getWidth() / BaseCode.world.getWidth()));
    } catch (AWTException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //
    // hero.registerWeapon(new SpreadFireWeapon(hero));
    // hero.registerWeapon(new OverHeatWeapon(hero));
    // hero.registerWeapon(new LimitedAmmoWeapon(hero));

    world.initialize(hero);

    new DeveloperControls(hero);

    Stargate.addColor(Colors.Yellow);

    timer = new Timer(2000);
  }
 /**
  * 将指定字符串设为剪切板的内容,然后执行粘贴操作 将页面焦点切换到输入框后,将指定内容粘贴到输入框中
  *
  * @param string
  */
 public static void setAndctrlVClipboardData(String string) {
   StringSelection stringSelection = new StringSelection(string);
   Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
   Robot robot = null;
   try {
     robot = new Robot();
   } catch (AWTException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   robot.keyPress(KeyEvent.VK_CONTROL);
   robot.keyPress(KeyEvent.VK_V);
   robot.keyRelease(KeyEvent.VK_V);
   robot.keyRelease(KeyEvent.VK_CONTROL);
 }
Beispiel #22
0
 private void initScreen() {
   curGD = gdevs[curID];
   Rectangle bounds = getBounds();
   x = (int) bounds.getX();
   y = (int) bounds.getY();
   w = (int) bounds.getWidth();
   h = (int) bounds.getHeight();
   try {
     robot = new RobotDesktop(this);
     robot.setAutoDelay(10);
   } catch (AWTException e) {
     Debug.error("Can't initialize Java Robot on Screen " + curID + ": " + e.getMessage());
     robot = null;
   }
 }
Beispiel #23
0
  public void install() {
    try {
      if (trayIcon == null && SystemTray.isSupported()) {
        SystemTray systemTray = SystemTray.getSystemTray();
        Dimension size = systemTray.getTrayIconSize();
        trayIcon = createTrayIcon(size);
        systemTray.add(trayIcon);

        JPopupMenu popup = new JPopupMenu();
        trayIcon.setJPopupMenu(popup);
        createPopup(popup);
      }
    } catch (AWTException e) {
      e.printStackTrace();
    }
  }
Beispiel #24
0
  /**
   * Gets the local machine's Java robot object.
   *
   * @return
   */
  private Robot getRobot() {
    Robot r = null;
    final GraphicsDevice[] screenDevices =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    // if invalid screen device number... just set to 0
    if (!(deviceToControl >= 0 && deviceToControl < screenDevices.length)) {
      deviceToControl = 0;
    }

    // create it for the specified device
    try {
      r = new Robot(screenDevices[deviceToControl]);
    } catch (AWTException e) {
      e.printStackTrace();
    }
    return r;
  }
  public void takeScreenShot() {
    BufferedImage screencapture;

    try {
      screencapture = new Robot().createScreenCapture(guiFrame.getBounds());

      File file = new File(getMojamDir() + "/" + "screenShot" + sShotCounter++ + ".png");
      while (file.exists()) {
        file = new File(getMojamDir() + "/" + "screenShot" + sShotCounter++ + ".png");
      }

      ImageIO.write(screencapture, "png", file);
    } catch (AWTException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /** Provide password for window authentication */
  public static void windowAuthenticationPassword(MethodParameters model) {
    Robot robot;
    try {
      robot = new Robot();
      robot.keyPress(KeyEvent.VK_TAB);
      String letter = model.getData();
      for (int i = 0; i < letter.length(); i++) {
        boolean upperCase = Character.isUpperCase(letter.charAt(i));
        String KeyVal = Character.toString(letter.charAt(i));
        String variableName = "VK_" + KeyVal.toUpperCase();
        Class clazz = KeyEvent.class;
        Field field = clazz.getField(variableName);
        int keyCode = field.getInt(null);

        if (upperCase) {
          robot.keyPress(KeyEvent.VK_SHIFT);
        }

        robot.keyPress(keyCode);
        robot.keyRelease(keyCode);

        if (upperCase) {
          robot.keyRelease(KeyEvent.VK_SHIFT);
        }
      }
      robot.keyPress(KeyEvent.VK_ENTER);
    } catch (AWTException e) {

      MainTestNG.LOGGER.severe(e.getMessage());

    } catch (NoSuchFieldException e) {

      MainTestNG.LOGGER.severe(e.getMessage());
    } catch (SecurityException e) {

      MainTestNG.LOGGER.severe(e.getMessage());
    } catch (IllegalArgumentException e) {

      MainTestNG.LOGGER.severe(e.getMessage());
    } catch (IllegalAccessException e) {

      MainTestNG.LOGGER.severe(e.getMessage());
    }
  }
Beispiel #27
0
  public Tray() {

    if (SystemTray.isSupported()) {

      EventHandler EH = new EventHandler();

      SystemTray Tray = SystemTray.getSystemTray();
      Toolkit tk = Toolkit.getDefaultToolkit();
      Image img =
          tk.getImage(
              System.getProperty("user.dir")
                  + fileSeparator
                  + "res"
                  + fileSeparator
                  + "notica.png");

      PopupMenu menu = new PopupMenu();
      MenuItem action = new MenuItem("Nueva Nota");
      MenuItem Close = new MenuItem("Cerrar");

      action.addActionListener(EH.addNote());
      Close.addActionListener(EH.Cerrar());

      menu.add(action);
      menu.add(Close);

      TrayIcon ti = new TrayIcon(img, "Knote 1.0", menu);
      ti.setImageAutoSize(true);

      try {
        Tray.add(ti);

      } catch (AWTException ex) {
        ex.printStackTrace();
        System.out.println("Error AWTException " + ex.getMessage());
      }

    } else {
      System.out.println("System Tray is not supported");
      return;
    }
  }
Beispiel #28
0
  public static void main(String[] args) {
    try {
      Random ran = new Random();
      int num = ran.nextInt();
      Robot robot = new Robot();
      String format = "jpg";
      String fileName = "FullScreenshot" + num + "." + format;

      Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
      BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
      ImageIO.write(screenFullImage, format, new File(fileName));
      Process p =
          new ProcessBuilder("explorer.exe", "/select,C:\\screenshots\\" + fileName).start();

    } catch (AWTException e) {
      System.err.println(e.getMessage());
    } catch (IOException ex) {
      System.err.println(ex.getMessage());
    }
  }
Beispiel #29
0
  public FressaFunctions(Options options) {

    msg = options.getMessages(BUNDLE);

    try {
      robot = new Robot();
    } catch (java.awt.AWTException ex) {
      System.err.println("Unable to create java.awt.Robot: " + ex.getMessage());
    }

    formExchange = new TFormExchange(INITIAL_FORM_EXCHANGE_POS, msg.get("acc_exchangeBtnChar"));
    formKeyboard = new TFormKeyboard(options, this);

    noHandCursor = options.getBoolean(NO_HAND_CURSOR, false);
    forceRectangularShapes = options.getBoolean(FORCE_RECTANGLES, false);

    scanTimerSpan = options.getInt(SCAN_TIMER_SPAN, DEFAULT_TIMER_SPAN);
    scanIncludingArrowButtons = options.getBoolean(SCAN_INCLUDING_ARROWS, true);
    withChangeZoneButton = options.getBoolean(CHANGE_ZONE_BUTTON, false);
    scanArrowsAtEndOfActivity = options.getBoolean(SCAN_ARROWS_AT_END, false);
    scanFlagButton = options.getBoolean(SCAN_FLAG, false);
    jumpWellPlaced = options.getBoolean(JUMP_WELL_PLACED, true);
    showKeyboard = options.getBoolean(SHOW_KEYBOARD, true);
    changeZoneIfNoClick = options.getBoolean(CHANGE_ZONE_IF_NO_CLICK, false);
    autoScanOnStart = options.getBoolean(AUTO_SCAN_ON_START, false);
    directedScanOnStart = options.getBoolean(DIRECTED_SCAN_ON_START, false);
    autoAutoScan = options.getBoolean(AUTO_AUTO_SCAN, false);
    withSwaying = options.getBoolean(SWAYING, false);
    readLabels = options.getBoolean(READ_LABELS, false);
    withVoice = options.getBoolean(WITH_VOICE, false);

    if (withVoice) {
      /*
      fressaVoice=new FressaVoice();
      fressaVoice.start();
      readText(msg.get("acc_voiceGreeting"));
      withVoice=fressaVoice.xxxxrunning;
       */
    }
  }
 @Test
 public void testEntrarComLoginQualquer() {
   try {
     // fail("Not yet implemented");
     try {
       Thread.sleep(3000);
     } catch (Exception e) {
     }
     JButton botaoEntrar = telaLogin.getEntrar();
     Robot r = new Robot();
     r.delay(3000);
     Point p = botaoEntrar.getLocationOnScreen();
     r.mouseMove(p.x + botaoEntrar.getWidth() / 2, p.y + botaoEntrar.getHeight() / 2);
     r.mousePress(InputEvent.BUTTON1_MASK);
     r.delay(3000);
     r.mouseRelease(InputEvent.BUTTON1_MASK);
     r.delay(3000);
   } catch (AWTException exc) {
     exc.printStackTrace();
     fail("awt exception no teste da telaLogin clicar botao entrar");
   }
 }