How to make keyPress uppercase in Java?

元气小坏坏 提交于 2019-12-25 00:37:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!