Search code examples
javawindowsgoogle-chromefirefoxopera

Java - how to generate click on desktop 1 and desktop 2?


I have a KIOSK with 2 monitor connected to one PC for dependencies and third party compatibility issues, PC has to launch on startup as following:

a) Google Chrome in kiosk mode on both screens (no other application is accessable)

b) Firefox, Opera not in kiosk mode but has to run as hidden behind Google Chrome for some of there printing jobs

Problem:

But on every boot, Firefox, Opera always stay on top of Google Chrome, even those were not launched as kiosk mode.

I have written Java code on boot to burst fire some clicks, so that the front-end only shows Google Chrome but its not working.

Can anyone please fix the code? what is am i doing wrong? I need to send burst fire clicks on screen 1 (1024x768), screen 2 (1280x720).

import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.InputEvent;
public class kiosk {
  public static void main(String[] args) {
    try {
      Robot robot = new Robot();
      // Screen Adjust
      robot.setAutoDelay(500);
      robot.mouseMove(1270, 400);
      robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
      robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);        

      // Screens
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] gs = ge.getScreenDevices();
      for(GraphicsDevice curGs : gs) {
        DisplayMode dm = curGs.getDisplayMode();
        System.out.println(dm.getWidth() + " x " + dm.getHeight());
      }

    } catch (Exception e) {
      System.out.println(e);
    }
  }
}

enter image description here


Solution

  • it Works!

    import java.awt.DisplayMode;
    import java.awt.GraphicsConfiguration;
    import java.awt.GraphicsDevice;
    import java.awt.GraphicsEnvironment;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.event.InputEvent;
    
    public class kiosk {
      public static void main(String[] args) {
        try {
          // Screens
          int ScreenID = 0;
          GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
          GraphicsDevice[] gs = ge.getScreenDevices();
          for(GraphicsDevice curGs : gs) {
    
            // Get the Displays
            DisplayMode dm = curGs.getDisplayMode();
            int x = dm.getWidth();
            System.out.println(ScreenID + " :" + dm.getWidth() + " x " + dm.getHeight());
    
            // Burst fire now
            Robot robot = new Robot();
            robot.setAutoDelay(500);
            if(ScreenID>0) {         
              robot.mouseMove(1280 + (x/13), 70);
            } else {
              robot.mouseMove(x/13, 70);
            }
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);   
            ScreenID++;
    
          }            
    
        } catch (Exception e) {
          System.out.println(e);
        }
      }
    }