简体   繁体   中英

How to make keyPress uppercase in Java?

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?

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); 

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM