我有一個非常簡單的問題,或者至少我認爲它很簡單。目前我正在嘗試使用帶變量的機器人類。我的意思是以下(變量「通行證」的字符。)使用變量的Java機器人類
pass1 = 0;
pass2 = 0;
pass3 = 0;
pass4 = 0;
try{
Robot robot = new Robot();
robot.delay(2000);
robot.mouseMove(1318, 322);
robot.keyPress(pass1);
robot.keyPress(pass2);
robot.keyPress(pass3);
robot.keyPress(pass4);
} catch (AWTException e) {e.printStackTrace();}
當我運行程序時,我得到這個錯誤(記住,我只得到這個錯誤時代碼的一部分用 「PASS1,PASS2 ...等。」 是在它):
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid key code
at java.awt.Robot.checkKeycodeArgument(Unknown Source)
at java.awt.Robot.keyPress(Unknown Source)
at Cracker$2.mouseReleased(Cracker.java:117)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
如果PASS1-PASS4是炭灰,不應該'他們是pass1 ='0'等? – Solace
'0'是一個有效的值嗎?因爲那就是你傳給每個keyPress(傳遞#)的東西' – aliteralmind
@solace整數0可以轉換爲char。這仍然不一定使它們成爲機器人方法的有效參數值。 –