244 kCGScrollEventUnitLine, 245 k_JAVA_ROBOT_WHEEL_COUNT, wheelAmt); 246 247 if (event != NULL) { 248 CGEventPost(kCGSessionEventTap, event); 249 CFRelease(event); 250 } 251 } 252 253 /* 254 * Class: sun_lwawt_macosx_CRobot 255 * Method: keyEvent 256 * Signature: (IZ)V 257 */ 258 JNIEXPORT void JNICALL 259 Java_sun_lwawt_macosx_CRobot_keyEvent 260 (JNIEnv *env, jobject peer, jint javaKeyCode, jboolean keyPressed) 261 { 262 CGKeyCode keyCode = GetCGKeyCode(javaKeyCode); 263 264 if ((javaKeyCode >= java_awt_event_KeyEvent_VK_0) && 265 (javaKeyCode <= java_awt_event_KeyEvent_VK_9)) 266 { 267 AXUIElementRef elem = AXUIElementCreateSystemWide(); 268 AXUIElementPostKeyboardEvent(elem, (CGCharCode)0, keyCode, keyPressed); 269 CFRelease(elem); 270 } else { 271 /* 272 * JDK-8155740: AXUIElementPostKeyboardEvent posts correct key codes for 273 * number keys whereas CGEventPost posts Numpad keys for corresponding 274 * number key. Hence AXUIElementPostKeyboardEvent is used for posting 275 * numbers and CGEventCreateKeyboardEvent/CGEventPost is used for other 276 * keys. 277 * Key code for modifier key is required to distinguish between ALT and 278 * ALT-GR key for fixing issue 8155740. 279 */ 280 CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed); 281 if (event != NULL) { 282 CGEventPost(kCGSessionEventTap, event); 283 CFRelease(event); 284 } 285 } 286 } 287 288 /* 289 * Class: sun_lwawt_macosx_CRobot 290 * Method: nativeGetScreenPixels 291 * Signature: (IIIII[I)V 292 */ 293 JNIEXPORT void JNICALL 294 Java_sun_lwawt_macosx_CRobot_nativeGetScreenPixels 295 (JNIEnv *env, jobject peer, 296 jint x, jint y, jint width, jint height, jintArray pixels) 297 { 298 JNF_COCOA_ENTER(env); 299 300 jint picX = x; 301 jint picY = y; 302 jint picWidth = width; 303 jint picHeight = height; 304 305 CGRect screenRect = CGRectMake(picX, picY, picWidth, picHeight); | 244 kCGScrollEventUnitLine, 245 k_JAVA_ROBOT_WHEEL_COUNT, wheelAmt); 246 247 if (event != NULL) { 248 CGEventPost(kCGSessionEventTap, event); 249 CFRelease(event); 250 } 251 } 252 253 /* 254 * Class: sun_lwawt_macosx_CRobot 255 * Method: keyEvent 256 * Signature: (IZ)V 257 */ 258 JNIEXPORT void JNICALL 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); |