< 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
*** 263,285 **** * 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 --- 264,303 ---- * 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); + + /* + * 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 ((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); } ! } } /* * Class: sun_lwawt_macosx_CRobot * Method: nativeGetScreenPixels
< prev index next >