Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send CTRL+Z keyEvent in java using Robot class

Tags:

java

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.

like image 568
sayem siam Avatar asked Jan 28 '12 18:01

sayem siam


People also ask

Can Robot class handle Windows popup?

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.

What is VK in Robot class?

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.

What is KeyEvent Vk_control?

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.


1 Answers

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).
like image 132
ziesemer Avatar answered Sep 28 '22 18:09

ziesemer