我最近刚刚发现了 awt.Robot 库,我很高兴能够使用它。我以为我会对我的朋友开个小玩笑,让机器人按控制、alt、删除按锁定计算机按钮,但我无法让程序调出控制 alt 删除屏幕。
这是我的代码:
import java.awt.*;
import java.awt.event.KeyEvent;
public class Bot {
public static void main(String[] args)
{
try {
Robot bot = new Robot();
bot.delay(4000);
bot.keyPress(KeyEvent.VK_CONTROL);
bot.delay(100);
bot.keyPress(KeyEvent.VK_ALT);
bot.delay(100);
bot.keyPress(KeyEvent.VK_DELETE);
bot.delay(500);
bot.keyRelease(KeyEvent.VK_CONTROL);
bot.keyRelease(KeyEvent.VK_ALT);
bot.keyRelease(KeyEvent.VK_DELETE);
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void pressEnter(Robot bot)
{
bot.keyPress(KeyEvent.VK_ENTER);
bot.delay(40);
bot.keyRelease(KeyEvent.VK_ENTER);
}
}