在击键方面我还是比较新的。当我将字符转换为整数然后尝试使用机器人对其进行按键按下时,它不会打印出小写字母,而是将大写字母打印成小写字母。
我尝试通过将输入更改为全大写(使用 toUpperCase)来运行代码,这有效,但代码不会打印出大写字母。
import java.awt.Robot;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class typeWriter {
public static void main(String[] args) throws InterruptedException {
Scanner scan=new Scanner(System.in);
try {
String text6 = scan.nextLine();
String text = text6.toUpperCase();
char[] text1 = text.toCharArray();
Robot robot = new Robot();
int[] Charkey= new int[text1.length];
TimeUnit.SECONDS.sleep(scan.nextInt());
for(int i = 0; i<text1.length; i++) {
Charkey[i]=(int) text1[i];
}
for(int y = 0; y<text1.length; y++) {
robot.keyPress(Charkey[y]);
robot.keyRelease(Charkey[y]);
}
} catch (AWTException e) {
}
}
}
当我输入“Hello”时,我希望它输入“Hello”,但它输入的是“h5/”(没有 toUpperCase 修饰符)。如果我将字符串更改为全大写,它会打印出正确的单词,但都是小写的。我应该怎么办?
不负相思意
相关分类