How to trigger a tab event?

How do we know how to press the tab key by clicking on Java? I also want to know how to run the Shift + tab key programmatically in Java.

+8
java swing awt
source share
3 answers

The following example shows how to simulate a mouse and keystrokes in Java using the java.awt.Robot class.

try { Robot robot = new Robot(); // Simulate a mouse click robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); // Simulate a key press robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_SHIFT); } catch (AWTException e) { e.printStackTrace(); } 

My post has been edited to press SHIFT + TAB.

+14
source share

If you really just need to go to the next component, you can do:

 KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(); 
+4
source share

You can use Robot for this.

+3
source share

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


All Articles