【问题标题】:Java Using Robot to Output letters (Capitalized and uncapitalized)Java 使用 Robot 输出字母(大写和非大写)
【发布时间】:2015-11-10 13:38:57
【问题描述】:

我正在使用这种方法尝试将我的信件输入一个表格。虽然当 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!");
        }
    }
}

这不起作用,因为它只写小写。

【问题讨论】:

    标签: java methods awtrobot


    【解决方案1】:

    你应该这样做

    bot.delay(40);
    bot.keyPress(KeyEvent.VK_SHIFT);
    bot.keyPress(code);
    bot.keyRelease(code);
    bot.keyRelease(KeyEvent.VK_SHIFT);
    //rest of your code
    

    【讨论】:

    • 谢谢,伙计!非常简单的解决方案。我去试试这个。
    猜你喜欢
    • 2018-12-10
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-30
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多