import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class qq_focus {
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_Z);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_Z);
} catch (AWTException e) {
e.printStackTrace();
}
}
}
我需要频繁地从画图板中用snagit选择一个区域,拷贝到粘贴板,然后让qq聊天窗口获得光标,然后再用ctrl+v或鼠标粘贴,发送图片。这一系列动作如何用java实现?上面这个远远不能满足要求。
补充,如果qq聊天窗口已经有光标,则可以自动ctrl+v。
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class ctrl_v {
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.delay(5000);
robot.keyPress(KeyEvent.VK_CONTROL);
//robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
//robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_V);
} catch (AWTException e) {
e.printStackTrace();
}
}
}
总之,键盘动作越少越好。