最近一個(gè)項(xiàng)目中實(shí)現(xiàn)java項(xiàng)目中模擬點(diǎn)擊鍵盤效果,在此記錄一下
使用rebot可以實(shí)現(xiàn)文章來源:http://www.zghlxwxcb.cn/news/detail-531766.html
// 創(chuàng)建Robot對(duì)象
Robot robot = null;
try {
robot = new Robot();
// 按下ctrl鍵 實(shí)現(xiàn)ctrl+p打印效果
robot.keyPress(KeyEvent.VK_CONTROL);
// 按下p鍵
robot.keyPress(KeyEvent.VK_P);
// 釋放ctrl鍵
robot.keyRelease(KeyEvent.VK_CONTROL);
// 釋放p鍵
robot.keyRelease(KeyEvent.VK_P);
Thread.sleep(1500l);
// 按下enter鍵
robot.keyPress(KeyEvent.VK_ENTER);
// 釋放enter鍵
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
Java執(zhí)行exe程序(exe為autoit生成的腳本程序,fileName為傳入的參數(shù))文章來源地址http://www.zghlxwxcb.cn/news/detail-531766.html
String fileName = "C:\\Users\\lixin\\Documents\\report\\test.pdf";
Runtime.getRuntime().exec("C:\\Users\\lixin\\Desktop\\test.exe "+ fileName);
到了這里,關(guān)于Java實(shí)現(xiàn)鍵盤按鍵點(diǎn)擊效果的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!