使用java.awt.Robot键入字符串

我已经知道如何使用java.awt.Robot键入单个字符keyPress,如下所示。如何简单地

预定义String值? *

robot.keyPress(KeyEvent.VK_1);

robot.keyPress(KeyEvent.VK_1);

robot.keyPress(KeyEvent.VK_1);

// instead, enter String x = "111"

回答:

常见的解决方案是使用剪贴板:

String text = "Hello World";

StringSelection stringSelection = new StringSelection(text);

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

clipboard.setContents(stringSelection, stringSelection);

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_CONTROL);

robot.keyPress(KeyEvent.VK_V);

robot.keyRelease(KeyEvent.VK_V);

robot.keyRelease(KeyEvent.VK_CONTROL);

以上是 使用java.awt.Robot键入字符串 的全部内容, 来源链接: utcz.com/qa/398761.html

回到顶部