--- old/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m 2016-05-14 01:59:28.000000000 +0530 +++ new/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m 2016-05-14 01:59:28.000000000 +0530 @@ -33,6 +33,7 @@ #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. @@ -265,19 +266,36 @@ * 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); + /* + * JDK-8155740: AXUIElementPostKeyboardEvent posts 0 key code for all + * the modifier keys with key codes (16, 17,18, 20, 157) and also for + * newly added modifier key VK_ALT_GRAPH. But it posts correct key code + * for all the other keys. On the other hand CGEventCreateKeyboardEvent + * posts correct key code for all the keys except numeric keys (0 to 9). + * CGEventCreateKeyboardEvent posts wrong key codes for the number keys + * 0 to 9. Instead of posting number key codes it posts Numpad key codes + * for the corresponding number key. For example Numpad0 key is posted for + * number 0 and simillarly for remaining num keys. Based on this behaviour + * AXUIElementPostKeyboardEvent is used to post only numeric key events + * and CGEventCreateKeyboardEvent used for posting all other key events. + */ -#if 0 - CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed); - if (event != NULL) { - CGEventPost(kCGSessionEventTap, event); - CFRelease(event); + 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 { + CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed); + if (event != NULL) { + CGEventPost(kCGSessionEventTap, event); + CFRelease(event); + } } -#endif } /*