< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m

Print this page




 241 {
 242     CGEventRef event = CGEventCreateScrollWheelEvent(NULL,
 243                                             kCGScrollEventUnitLine,
 244                                             k_JAVA_ROBOT_WHEEL_COUNT, wheelAmt);
 245 
 246     if (event != NULL) {
 247         CGEventPost(kCGSessionEventTap, event);
 248         CFRelease(event);
 249     }
 250 }
 251 
 252 /*
 253  * Class:     sun_lwawt_macosx_CRobot
 254  * Method:    keyEvent
 255  * Signature: (IZ)V
 256  */
 257 JNIEXPORT void JNICALL
 258 Java_sun_lwawt_macosx_CRobot_keyEvent
 259 (JNIEnv *env, jobject peer, jint javaKeyCode, jboolean keyPressed)
 260 {
 261     /*
 262      * Well, using CGEventCreateKeyboardEvent/CGEventPost would have been
 263      * a better solution, however, it gives me all kinds of trouble and I have
 264      * no idea how to solve them without inserting delays between simulated
 265      * events. So, I've ended up disabling it and opted for another approach
 266      * that uses Accessibility API instead.
 267      */
 268     CGKeyCode keyCode = GetCGKeyCode(javaKeyCode);
 269     AXUIElementRef elem = AXUIElementCreateSystemWide();
 270     AXUIElementPostKeyboardEvent(elem, (CGCharCode)0, keyCode, keyPressed);
 271     CFRelease(elem);
 272 
 273 
 274 #if 0
 275     CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed);
 276     if (event != NULL) {
 277         CGEventPost(kCGSessionEventTap, event);
 278         CFRelease(event);
 279     }
 280 #endif
 281 }
 282 
 283 /*
 284  * Class:     sun_lwawt_macosx_CRobot
 285  * Method:    nativeGetScreenPixels
 286  * Signature: (IIIII[I)V
 287  */
 288 JNIEXPORT void JNICALL
 289 Java_sun_lwawt_macosx_CRobot_nativeGetScreenPixels
 290 (JNIEnv *env, jobject peer,
 291  jint x, jint y, jint width, jint height, jintArray pixels)
 292 {
 293     JNF_COCOA_ENTER(env);
 294 
 295     jint picX = x;
 296     jint picY = y;
 297     jint picWidth = width;
 298     jint picHeight = height;
 299 
 300     CGRect screenRect = CGRectMake(picX, picY, picWidth, picHeight);




 241 {
 242     CGEventRef event = CGEventCreateScrollWheelEvent(NULL,
 243                                             kCGScrollEventUnitLine,
 244                                             k_JAVA_ROBOT_WHEEL_COUNT, wheelAmt);
 245 
 246     if (event != NULL) {
 247         CGEventPost(kCGSessionEventTap, event);
 248         CFRelease(event);
 249     }
 250 }
 251 
 252 /*
 253  * Class:     sun_lwawt_macosx_CRobot
 254  * Method:    keyEvent
 255  * Signature: (IZ)V
 256  */
 257 JNIEXPORT void JNICALL
 258 Java_sun_lwawt_macosx_CRobot_keyEvent
 259 (JNIEnv *env, jobject peer, jint javaKeyCode, jboolean keyPressed)
 260 {







 261         CGKeyCode keyCode = GetCGKeyCode(javaKeyCode);




 262         

 263     CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed);
 264     if (event != NULL) {
 265         CGEventPost(kCGSessionEventTap, event);
 266         CFRelease(event);
 267     }

 268 }
 269 
 270 /*
 271  * Class:     sun_lwawt_macosx_CRobot
 272  * Method:    nativeGetScreenPixels
 273  * Signature: (IIIII[I)V
 274  */
 275 JNIEXPORT void JNICALL
 276 Java_sun_lwawt_macosx_CRobot_nativeGetScreenPixels
 277 (JNIEnv *env, jobject peer,
 278  jint x, jint y, jint width, jint height, jintArray pixels)
 279 {
 280     JNF_COCOA_ENTER(env);
 281 
 282     jint picX = x;
 283     jint picY = y;
 284     jint picWidth = width;
 285     jint picHeight = height;
 286 
 287     CGRect screenRect = CGRectMake(picX, picY, picWidth, picHeight);


< prev index next >