hey i want to create my own auto login for emails and CO, as an exercise because i am still a beginner. I use the Java Robot for this and since I know that it doesn't have all the special characters I want to catch some of the characters before the robot gets them. I do that too (I think).But I always get the "Invalid key code" error. Does anyone have any advice ? And i use a german keybord
import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
public class Login {
public static void main (String [] args) {
/* args 0 is for the website
args 1 is for the email adresse
args 2 is for the password
*/
try {
// Process p1= Runtime.getRuntime().exec("\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\"");
Process p1= Runtime.getRuntime().exec("\"C:\\ProgramFiles \\Notepad++\\notepad++.exe\""); // i use notepad here for testing
Thread.sleep(100);
write(args[0]);
Thread.sleep(300);
write(args[1]);
Thread.sleep(300);
write(args[2]);
// p1.destroy();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void write(String s)
{
try
{
Robot r = new Robot();
int i = 0;
char[] buchstaben = s.toCharArray();
String AT = "@";
while (i<s.length())
{
System.out.println("KeyEvent ist: "+ buchstaben[i]);
if((String.valueOf(buchstaben[i]).contains(AT))==true)
{
r.keyPress(KeyEvent.VK_AT);
// r.keyPress(KeyEvent.VK_ALT_GRAPH);
// r.keyPress('Q');
r.delay(250);
r.keyRelease(KeyEvent.VK_AT);
// r.keyRelease(KeyEvent.VK_ALT_GRAPH);
// r.keyRelease(KeyEvent.VK_Q);
i++;
}
if(Character.isUpperCase(buchstaben[i]))
{
r.keyPress(KeyEvent.VK_SHIFT);
}
synchronized(r)
{
r.keyPress(Character.toUpperCase(buchstaben[i]));
r.delay(250);
r.keyRelease(Character.toUpperCase(buchstaben[i]));
}
if(Character.isUpperCase(buchstaben[i]))
{
r.keyRelease(KeyEvent.VK_SHIFT);
}
i++;
}
r.keyPress(KeyEvent.VK_ENTER);
r.delay(250);
r.keyRelease(KeyEvent.VK_ENTER);
}
catch(AWTException e)
{
System.err.println(e);
}
}
}
Exception in thread "main" java.lang.IllegalArgumentException: Invalid key code
at sun.awt.windows.WRobotPeer.keyPress(Native Method)
at java.awt.Robot.keyPress(Robot.java:354)
at Login.write(Login.java:53)
at Login.main(Login.java:21)