Press the Java key

I was wondering if it is possible to press a key with Java. Not quite sure how to approach this. There must be some type of class that has like sendKeyPress (); or something like that.

+6
source share
2 answers

You can do this easily with the Robot class. It practically presses a button, without special targeting or anything else.

For example, to press Enter :

 Robot r = new Robot(); r.keyPress(KeyEvent.VK_ENTER); r.keyRelease(KeyEvent.VK_ENTER); 
+12
source
 Action act = new Action(driver); act.sendkeys(Keys.ENTER).build().perform(); 
0
source

Source: https://habr.com/ru/post/920273/


All Articles