diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java index 5dba06cb612b..808998e4c2e0 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java @@ -34,6 +34,7 @@ import sun.awt.CGraphicsDevice; final class CRobot implements RobotPeer { private static final int MOUSE_LOCATION_UNKNOWN = -1; + private static final int DEFAULT_SAFE_DELAY_MILLIS = 50; private final CGraphicsDevice fDevice; private int mouseLastX = MOUSE_LOCATION_UNKNOWN; @@ -50,7 +51,12 @@ final class CRobot implements RobotPeer { */ CRobot(CGraphicsDevice d) { fDevice = d; - initRobot(); + int safeDelayMillis = Integer.getInteger( + "sun.awt.osx.RobotSafeDelayMillis", DEFAULT_SAFE_DELAY_MILLIS); + if (safeDelayMillis < 0) { + safeDelayMillis = DEFAULT_SAFE_DELAY_MILLIS; + } + initRobot(safeDelayMillis); } /** @@ -187,7 +193,7 @@ final class CRobot implements RobotPeer { return c; } - private native void initRobot(); + private native void initRobot(int safeDelayMillis); private native void mouseEvent(int lastX, int lastY, int buttonsState, boolean isButtonsDownState, boolean isMouseMove); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m index 147af2b7a7f0..9bcc941a8c79 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m @@ -63,6 +63,7 @@ static NSTimeInterval gsLastClickTime; static int gsEventNumber; static int* gsButtonEventNumber; static NSTimeInterval gNextKeyEventTime; +static NSTimeInterval safeDelay; static inline CGKeyCode GetCGKeyCode(jint javaKeyCode); @@ -99,17 +100,17 @@ static inline void autoDelay(BOOL isMove) { [NSThread sleepForTimeInterval:delay]; } } - gNextKeyEventTime = [[NSDate date] timeIntervalSinceReferenceDate] + 0.050; + gNextKeyEventTime = [[NSDate date] timeIntervalSinceReferenceDate] + safeDelay; } /* * Class: sun_lwawt_macosx_CRobot * Method: initRobot - * Signature: (V)V + * Signature: (I)V */ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CRobot_initRobot -(JNIEnv *env, jobject peer) +(JNIEnv *env, jobject peer, jint safeDelayMillis) { // Set things up to let our app act like a synthetic keyboard and mouse. // Always set all states, in case Apple ever changes default behaviors. @@ -138,6 +139,7 @@ Java_sun_lwawt_macosx_CRobot_initRobot gsClickCount = 0; gsLastClickTime = 0; gNextKeyEventTime = 0; + safeDelay = (NSTimeInterval)safeDelayMillis/1000; gsEventNumber = ROBOT_EVENT_NUMBER_START; gsButtonEventNumber = (int*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(int), gNumberOfButtons);