getExtendedKeyCodeForChar está printnado errado:
Usando essa classe de teste:
package test;
import iRobot.iRobot_Functions;
public class Test {
public static void main(String[] args) {
String admUsr = "HOMP\\adm03!@";
iRobot_Functions irf = new iRobot_Functions();
irf.Wait(3000);
irf.Send(admUsr);
System.out.println(admUsr);
}
}
package iRobot;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import java.io.IOException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class iRobot_Functions {
Robot r;
public void Wait(int i)
{
Robot r;
try {
r = new Robot();
r.delay(i);
} catch (AWTException ex) {
Logger.getLogger(iRobot_Functions.class.getName()).log(Level.SEVERE, null, ex);
}
}
// pressionar teclas
public void Press(int keyCode) {
try {
r = new Robot();
r.keyPress(keyCode);
r.delay(200);
r.keyRelease(keyCode);
r.delay(200);
} catch (AWTException ex) {
Logger.getLogger(iRobot_Functions.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void Send(String s) {
if (null == s) return;
Robot r = null;
char[] chars = s.toCharArray();
try {
for (char c : chars) {
int code = c;
int keyCode = KeyEvent.getExtendedKeyCodeForChar(code);
r = new Robot();
r.delay(40);
r.keyPress(keyCode);
r.keyRelease(keyCode);
}
} catch (AWTException ex) {
System.err.println(ex.getMessage());
}
}
}
No system.out.println está printando certo HOMP\adm03!@
Mas no Send está printnado errado homp\adm0312
Ignorando shifts e usando homp ao inves de HOMP 1 ao inves de ! 2 ao inves de @
Alguem sabe como arrumar isso?