问题
I am using robotframework for automation of desktop application. I'm trying to do a right click on Mac Sierra and then use send keys to select the items generated on the context menu. I have activated mouse keys settings from the accessibility setting so that NUMPAD 5 will behave as a right click on mouse pointer. The problem is when I use this command it actually does a right click but when I try to use the send keys command the context menu disappears. So, I'm not able to select items from the context menu. Here is the code for right click:
public void pressCtrl(String key) throws Exception {
if(key.contains("NUMPAD")){
int keyvalue = key.charAt(6);
int keycode = keyvalue + 48;
assertTrue(
String.format("'%c' is not an alphanumeric character", keycode),
(keycode >=KeyEvent.VK_A && keycode <=KeyEvent.VK_Z) || (keycode >=KeyEvent.VK_0 && keycode <=KeyEvent.VK_9) || (keycode >=KeyEvent.VK_NUMPAD0 && keycode <=KeyEvent.VK_NUMPAD9)
);
System.out.println("Press CTRL+"+key);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(keycode);
robot.delay(50);
robot.keyRelease(keycode);
robot.keyRelease(KeyEvent.VK_CONTROL);
So the sequence of command on robotframework is :
Press Ctrl NUMPAD5
Send Keys E
Press Enter
What I think and have tried:
I'm not able to identify why the context menu generated from the right click disappears while trying to use the send keys. I have tried this combination manually, it seems there is certain timing when right click disappears when key is released. I tried difference combinations of timings with my automation script but all the time I find same behavior. The same script and java code works fine on Windows.
来源:https://stackoverflow.com/questions/40812032/numpad-5-for-right-click-on-mac-is-not-working-using-robotframework