我刚刚发现了关于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);
}
}