Replication of mouse behavior in code

This is due to the question: Focus problems with JDK7 and built-in components .

During workarounds, we noticed that if we clicked on another component in the window (i.e. the shortcut showing the image) and then click on the text fields (in the Flash application), everything seemed to work fine. So I tried to reproduce this from code, but was not successful.

Basically, when a mouse is detected hovering over a text field, I get a notification from Flash and I request focus on the shortcut, so when the user clicks on the actual field, the label already has focus.

I will request focus as follows:

draggableComponent.requestFocus(); 

Where draggableComponent is the shortcut I talked about. I think this is not equivalent to clicking on a shortcut. What am I missing?

0
source share
1 answer

Finally, I found the answer here .

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_A); robot.keyRelease(KeyEvent.VK_A); } catch (AWTException e) { e.printStackTrace(); } 

The Robot class has given me everything I need.

0
source

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


All Articles