如何使用机器人类在Java中发送CTRL + Z keyEvent

问题描述 投票:8回答:1

我正在使用Java Robot类来发送键事件。我尝试了robot.keyPress()功能。但是我不知道如何发送CTRL + z keyEvent。

java
1个回答
13
投票
robot.keyPress(KeyEvent.VK_CONTROL)
robot.keyPress(KeyEvent.VK_Z)
// CTRL+Z is now pressed (receiving application should see a "key down" event.)
robot.keyRelease(KeyEvent.VK_Z)
robot.keyRelease(KeyEvent.VK_CONTROL)
// CTRL+Z is now released (receiving application should now see a "key up" event - as well as a "key pressed" event).
© www.soinside.com 2019 - 2024. All rights reserved.