0

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 :(

ccit
  • 309
  • 1
  • 3
  • 12
  • In short, not possible (especially for keyboard input) however see this similar question: http://stackoverflow.com/questions/7910510/differentiate-between-robot-mouseclick-and-human-mouse-click – David Kroukamp Jul 15 '12 at 15:06
  • The link is looking for detection as a step for prevention for external uses (like aimbot etc), which is arguably impossible. What I am looking for is detection for my own use of `java.awt.Robot`, not other people using it, so I wouldn't mind adjusting how/where/when I use `Robot` to generate events in order to differentiate whether the user generated the event by keyboard/mouse, or my application did that through `Robot`. No user involved in the `Robot` part. So there must be some sort of a hack to differentiate them – ccit Jul 15 '12 at 15:16

0 Answers0