我正在使用此方法尝试将我的字母输入到表单中。虽然当char被转换回chars时,它们不会被大写。什么是最有效的特定字母大写方式?
我的尝试:
private static void type(String s) throws AWTException
{
Robot bot = new Robot();
byte[] bytes = s.getBytes();
for (byte b : bytes)
{
int code = b;
try
{
if (code > 96 && code < 123)
code = code - 32;
bot.delay(40);
bot.keyPress(code);
bot.keyRelease(code);
}
catch(Exception e)
{
System.out.println("Could not read code: " + code + ". Report this to MrGermanrain!");
}
}
}
这不起作用,因为它只写了小写。
答案 0 :(得分:0)
你应该做
bot.delay(40);
bot.keyPress(KeyEvent.VK_SHIFT);
bot.keyPress(code);
bot.keyRelease(code);
bot.keyRelease(KeyEvent.VK_SHIFT);
//rest of your code