< 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
*** 72,81 **** --- 73,84 ---- static void PostMouseEvent(const CGPoint point, CGMouseButton button, CGEventType type, int clickCount, int eventNumber); static int GetClickCount(BOOL isDown); + static BOOL IsModifierKey(jint javaKeyCode); + static void CreateJavaException(JNIEnv* env, CGError err) { // Throw a java exception indicating what is wrong. NSString* s = [NSString stringWithFormat:@"Robot: CGError: %d", err];
*** 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 --- 266,298 ---- * 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 modifier keys and hence it is used ! * to post modifier key events and AXUIElementPostKeyboardEvent is used to ! * post all the remaining key events. ! */ ! if (IsModifierKey(javaKeyCode)) { CGEventRef event = CGEventCreateKeyboardEvent(NULL, keyCode, keyPressed); if (event != NULL) { CGEventPost(kCGSessionEventTap, event); CFRelease(event); } ! } else { ! AXUIElementRef elem = AXUIElementCreateSystemWide(); ! AXUIElementPostKeyboardEvent(elem, (CGCharCode)0, keyCode, keyPressed); ! CFRelease(elem); ! } } /* * Class: sun_lwawt_macosx_CRobot * Method: nativeGetScreenPixels
*** 382,386 **** --- 395,414 ---- } } return gsClickCount; } + + static BOOL IsModifierKey(jint javaKeyCode) { + + switch (javaKeyCode) { + case java_awt_event_KeyEvent_VK_SHIFT: + case java_awt_event_KeyEvent_VK_CONTROL: + case java_awt_event_KeyEvent_VK_ALT: + case java_awt_event_KeyEvent_VK_CAPS_LOCK: + case java_awt_event_KeyEvent_VK_META: + case java_awt_event_KeyEvent_VK_ALT_GRAPH: + return YES; + } + + return NO; + }
< prev index next >