如何在Java中使用keyPress大写?

时间:2015-03-27 23:33:14

标签: java keypress keyevent capslock

localRobot.keyPress(KeyEvent.VK_F);

我不知道如何使这个按键成为大写的按键。我试图按VK_SHIFT并在之后发布,但这并不起作用。是否可以按下大写锁定按钮?如果是这样,我该怎么办?它只是VK_CAPS吗?

2 个答案:

答案 0 :(得分:1)

我相信这可行。按下换档按钮,按下然后释放。

localrobot.keyPress (KeyEvent.VK_SHIFT); 
localrobot.keyPress (keyCode); //Your keycode(your letter)

localrobot.keyRelease (KeyEvent.VK_SHIFT); 
localrobot.keyRelease (keyCode); 

答案 1 :(得分:1)

尝试:

localRobot.keyPress(KeyEvent.VK_SHIFT);
localRobot.keyPress(KeyEvent.VK_F);
localRobot.keyRelease(KeyEvent.VK_F);
localRobot.keyRelease(KeyEvent.VK_SHIFT);

或者:

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