问题
localRobot.keyPress(KeyEvent.VK_F);
I have no clue how to make this keypress an uppercase keypress. I attempted to press VK_SHIFT and release afterwards, however that didn't work. Would it work to press the capslock button? If so, how do I do it? Is it just VK_CAPS?
回答1:
I believe this might work. It presses the shift button, presses yours then releases.
localrobot.keyPress (KeyEvent.VK_SHIFT);
localrobot.keyPress (keyCode); //Your keycode(your letter)
localrobot.keyRelease (KeyEvent.VK_SHIFT);
localrobot.keyRelease (keyCode);
回答2:
Try:
localRobot.keyPress(KeyEvent.VK_SHIFT);
localRobot.keyPress(KeyEvent.VK_F);
localRobot.keyRelease(KeyEvent.VK_F);
localRobot.keyRelease(KeyEvent.VK_SHIFT);
Or:
localRobot.keyPress(KeyEvent.VK_CAPS_LOCK);
localRobot.keyRelease(KeyEvent.VK_CAPS_LOCK);
localRobot.keyPress(KeyEvent.VK_F);
localRobot.keyRelease(KeyEvent.VK_F);
localRobot.keyPress(KeyEvent.VK_CAPS_LOCK);
localRobot.keyRelease(KeyEvent.VK_CAPS_LOCK);
来源:https://stackoverflow.com/questions/29311831/how-to-make-keypress-uppercase-in-java