< prev index next >
src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m
Print this page
@@ -264,22 +264,31 @@
* 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);
-
+// 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 and hence it is used to post
+ * all the key events instead of AXUIElementPostKeyboardEvent.
+ * Key code for modifier key is required to distinguish between ALT and
+ * ALT-GR key for fixing issue 8155740.
+ */
-#if 0
- CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed);
+ CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
+ CGEventRef event = CGEventCreateKeyboardEvent(source, keyCode, keyPressed);
if (event != NULL) {
CGEventPost(kCGSessionEventTap, event);
CFRelease(event);
}
-#endif
}
/*
* Class: sun_lwawt_macosx_CRobot
* Method: nativeGetScreenPixels
< prev index next >