The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > Simulating Events  [2 examples]

e635. Simulating Mouse and Key Presses

This feature is useful for tools that test windowing applications.
    try {
        Robot robot = new Robot();
    
        // Simulate a mouse click
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
    
        // Simulate a key press
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
    } catch (AWTException e) {
    }

 Related Examples
e634. Moving the Cursor on the Screen

See also: Colors    Components    Containers    Cursors    Drawing    Events    Focus    Frames    GridBagLayout    Images    Shapes    Text    The Screen   


© 2002 Addison-Wesley.