2013년 7월 15일 월요일

우연히 발견한 Java 기본클래스 java.awt.Robot

무심코 자바 api를 보다가 발견한 클래스
마우스와 키보드 입력을 자동으로 동작하기 위해 만들어진 듯 하다.
하지만 특정 플랫폼에서 권한관련 문제로 AWTException이 발생할 수 있다고 함
(클래스의 인스턴스 생성시 익셉션 발생함)
매소드 구성을 보니  마우스 매크로 프로그램을 보는 것이 아닌가 싶을 정도로 사용법이 간단하다.

BufferedImagecreateScreenCapture(Rectangle screenRect)
          Creates an image containing pixels read from the screen.
 voiddelay(int ms)
          Sleeps for the specified time.
 intgetAutoDelay()
          Returns the number of milliseconds this Robot sleeps after generating an event.
 ColorgetPixelColor(int x, int y)
          Returns the color of a pixel at the given screen coordinates.
 booleanisAutoWaitForIdle()
          Returns whether this Robot automatically invokes waitForIdle after generating an event.
 voidkeyPress(int keycode)
          Presses a given key.
 voidkeyRelease(int keycode)
          Releases a given key.
 voidmouseMove(int x, int y)
          Moves mouse pointer to given screen coordinates.
 voidmousePress(int buttons)
          Presses one or more mouse buttons.
 voidmouseRelease(int buttons)
          Releases one or more mouse buttons.
 voidmouseWheel(int wheelAmt)
          Rotates the scroll wheel on wheel-equipped mice.
 voidsetAutoDelay(int ms)
          Sets the number of milliseconds this Robot sleeps after generating an event.
 voidsetAutoWaitForIdle(boolean isOn)
          Sets whether this Robot automatically invokes waitForIdle after generating an event.
 StringtoString()
          Returns a string representation of this Robot.
 voidwaitForIdle()
          Waits until all events currently on the event queue have been processed.

간단하긴 하지만 상황에 따라 유용한 클래스라고 생각함!

댓글 없음:

댓글 쓰기