2
我正在使用此方法嘗試將我的字母輸入到表單中。儘管當字符被轉換回字符時,它們不會被大寫。將特定字母大寫的最有效方法是什麼?Java使用機器人輸出字母(大寫和非大寫)
我嘗試:
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!");
}
}
}
這並沒有工作,因爲它只是寫小寫。
謝謝,夥計!很簡單的解決方案我會去爭取一下。 –