259 Java_sun_lwawt_macosx_CRobot_keyEvent 260 (JNIEnv *env, jobject peer, jint javaKeyCode, jboolean keyPressed) 261 { 262 CGKeyCode keyCode = GetCGKeyCode(javaKeyCode); 263 264 CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed); 265 if (event != NULL) { 266 CGEventPost(kCGSessionEventTap, event); 267 CFRelease(event); 268 } 269 } 270 271 /* 272 * Class: sun_lwawt_macosx_CRobot 273 * Method: nativeGetScreenPixels 274 * Signature: (IIIII[I)V 275 */ 276 JNIEXPORT void JNICALL 277 Java_sun_lwawt_macosx_CRobot_nativeGetScreenPixels 278 (JNIEnv *env, jobject peer, 279 jint x, jint y, jint width, jint height, jintArray pixels) 280 { 281 JNF_COCOA_ENTER(env); 282 283 jint picX = x; 284 jint picY = y; 285 jint picWidth = width; 286 jint picHeight = height; 287 288 CGRect screenRect = CGRectMake(picX, picY, picWidth, picHeight); 289 CGImageRef screenPixelsImage = CGWindowListCreateImage(screenRect, 290 kCGWindowListOptionOnScreenOnly, 291 kCGNullWindowID, kCGWindowImageDefault); 292 293 if (screenPixelsImage == NULL) { 294 return; 295 } 296 297 // get a pointer to the Java int array 298 void *jPixelData = (*env)->GetPrimitiveArrayCritical(env, pixels, 0); 299 CHECK_NULL(jPixelData); 300 301 // create a graphics context around the Java int array 302 CGColorSpaceRef picColorSpace = CGColorSpaceCreateWithName( 303 kCGColorSpaceGenericRGB); 304 CGContextRef jPicContextRef = CGBitmapContextCreate( 305 jPixelData, 306 picWidth, picHeight, 307 8, picWidth * sizeof(jint), 308 picColorSpace, | 259 Java_sun_lwawt_macosx_CRobot_keyEvent 260 (JNIEnv *env, jobject peer, jint javaKeyCode, jboolean keyPressed) 261 { 262 CGKeyCode keyCode = GetCGKeyCode(javaKeyCode); 263 264 CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed); 265 if (event != NULL) { 266 CGEventPost(kCGSessionEventTap, event); 267 CFRelease(event); 268 } 269 } 270 271 /* 272 * Class: sun_lwawt_macosx_CRobot 273 * Method: nativeGetScreenPixels 274 * Signature: (IIIII[I)V 275 */ 276 JNIEXPORT void JNICALL 277 Java_sun_lwawt_macosx_CRobot_nativeGetScreenPixels 278 (JNIEnv *env, jobject peer, 279 jint x, jint y, jint width, jint height, jdouble scale, jintArray pixels) 280 { 281 JNF_COCOA_ENTER(env); 282 283 jint picX = x; 284 jint picY = y; 285 jint picWidth = width; 286 jint picHeight = height; 287 288 CGRect screenRect = CGRectMake(picX / scale, picY / scale, 289 picWidth / scale, picHeight / scale); 290 CGImageRef screenPixelsImage = CGWindowListCreateImage(screenRect, 291 kCGWindowListOptionOnScreenOnly, 292 kCGNullWindowID, kCGWindowImageDefault); 293 294 if (screenPixelsImage == NULL) { 295 return; 296 } 297 298 // get a pointer to the Java int array 299 void *jPixelData = (*env)->GetPrimitiveArrayCritical(env, pixels, 0); 300 CHECK_NULL(jPixelData); 301 302 // create a graphics context around the Java int array 303 CGColorSpaceRef picColorSpace = CGColorSpaceCreateWithName( 304 kCGColorSpaceGenericRGB); 305 CGContextRef jPicContextRef = CGBitmapContextCreate( 306 jPixelData, 307 picWidth, picHeight, 308 8, picWidth * sizeof(jint), 309 picColorSpace, |