2017-10-18 2 views
0

사용자에 관계없이 타이밍에 따라 마우스 커서를 특정 좌표로 가져 오는 프로그램을 작성하려고합니다. 로봇을 사용하여 간단한 코드를 작성했지만 문제가 발생했습니다 ... 두 개의 모니터가 있는데 커서가 현재 어떤 모니터에 있는지에 따라 커서가 잘못 움직입니다. 문제를 해결하는 방법을 알려주십시오. 아래의 코드는 내가 만들려고 한 것입니다JAVA Robot mouseMove 2 모니터

...

GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); 

    GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices(); 

    for(int i=0; i < graphicsDevices.length; i++) 
    { 
     System.out.println(graphicsDevices[i]);    
    } 

    try { 

     //Robot robot = new Robot(MouseInfo.getPointerInfo().getDevice());    

     Robot robot = new Robot();    

     while(true) 
     { 
      robot.mouseMove(-1640, -3); 

      robot.mousePress(InputEvent.BUTTON1_MASK); 
      robot.mouseRelease(InputEvent.BUTTON1_MASK); 

      Thread.sleep(10000); 
     } 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

답변

0

당신은 해상도를 얻을 수의 아이디어로 작업하고 거기에서 이동해야합니다. ABSOLUTE이 수행 중이며 다른 설정에서 다르게 작동합니다.

Robot robot = new Robot(); 
robot.mouseMove (width-10, height+3); 

그래서 당신은 모니터의 사양에 상대적으로 이동합니다 :

당신은 당신이 할 수 거기에서이 코드

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); 
int width = gd.getDisplayMode().getWidth(); 
int height = gd.getDisplayMode().getHeight(); 

를 사용해야합니다. 내가 도왔 으면 좋겠어.