I am using Java Robot class to send keyevents. I tried robot.keyPress()
function. But I could not figure out how to send CTRL+z keyEvent.
Robot class is a java based utility which emulates the keyboard and mouse actions and can be effectively used to handling window based pop up with the help of keyboard events. The keyPress and keyRelease methods simulate the user pressing and releasing a certain key on the keyboard respectively.
VK_META and META_MASK are defined in KeyEvent and InputEvent classes. They both define the META key as a standalone key pressed and as a modifier used pressing another key respectively. The META key is a key used in old keyboards and now can be emulated using the Windows Key.
keyRelease(KeyEvent. VK_CONTROL); For Releasing the press effect on the key, If you have pressed a key using robot. keyPress(KeyEvent. VK_CONTROL); Then you should Release it too, otherwise once your java application runs, your keyboard has will continue with virtually CTRL key pressed.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With