< prev index next >

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

Print this page

        

*** 31,40 **** --- 31,41 ---- #import "CRobotKeyCode.h" #import "LWCToolkit.h" #import "sun_lwawt_macosx_CRobot.h" #import "java_awt_event_InputEvent.h" + #import "java_awt_event_KeyEvent.h" #import "sizecalc.h" // Starting number for event numbers generated by Robot. // Apple docs don't mention at all what are the requirements // for these numbers. It seems that they must be higher
*** 256,285 **** */ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CRobot_keyEvent (JNIEnv *env, jobject peer, jint javaKeyCode, jboolean keyPressed) { - /* - * Well, using CGEventCreateKeyboardEvent/CGEventPost would have been - * a better solution, however, it gives me all kinds of trouble and I have - * no idea how to solve them without inserting delays between simulated - * events. So, I've ended up disabling it and opted for another approach - * that uses Accessibility API instead. - */ CGKeyCode keyCode = GetCGKeyCode(javaKeyCode); AXUIElementRef elem = AXUIElementCreateSystemWide(); AXUIElementPostKeyboardEvent(elem, (CGCharCode)0, keyCode, keyPressed); CFRelease(elem); - #if 0 CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed); if (event != NULL) { CGEventPost(kCGSessionEventTap, event); CFRelease(event); } ! #endif } /* * Class: sun_lwawt_macosx_CRobot * Method: nativeGetScreenPixels --- 257,291 ---- */ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CRobot_keyEvent (JNIEnv *env, jobject peer, jint javaKeyCode, jboolean keyPressed) { CGKeyCode keyCode = GetCGKeyCode(javaKeyCode); + + if ((javaKeyCode >= java_awt_event_KeyEvent_VK_0) && (javaKeyCode <= java_awt_event_KeyEvent_VK_9)) + { AXUIElementRef elem = AXUIElementCreateSystemWide(); AXUIElementPostKeyboardEvent(elem, (CGCharCode)0, keyCode, keyPressed); CFRelease(elem); + } else { + /* + * JDK-8155740: AXUIElementPostKeyboardEvent posts correct key codes for + * number keys whereas CGEventPost posts Numpad keys for corresponding + * number key. Thereofore AXUIElementPostKeyboardEvent is used for posting + * numbers and CGEventCreateKeyboardEvent/CGEventPost is used for other + * keys. + * Key code for modifier key is required to distinguish between ALT and + * ALT-GR key for fixing issue 8155740. + */ CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed); if (event != NULL) { CGEventPost(kCGSessionEventTap, event); CFRelease(event); } ! } } /* * Class: sun_lwawt_macosx_CRobot * Method: nativeGetScreenPixels
< prev index next >