In Java, you can listen for key/mouse events generated by the user keyboard/mouse. Also, Java allows you to generate key/mouse events using the java.awt.Robot
, and these events can be captured by the same listeners. How can you differentiate between events generated by the user keyboard/mouse, and events generated by java.awt.Robot
. I examined event.getSource()
, but it seem that the event source for both is the same frame. Any other way to tell which one triggered the event?
Edit: Since this question is closed (cannot answer it), and the duplicate is not the answer. You can detect Robot events generated by your own application by setting a flag (multiple flags if needed) before generating the event using Robot, then check them when an event happen in the listener and rest them after handling them. This is not the best way, but it is possible. I was looking for a better way since it was in the same context of the application, but the one who closed the question made a rushed decision closing the question :(