Results 1 to 2 of 2
  1. #1
    kusanagi97 is offline Member
    Join Date
    Oct 2009
    Rep Power

    Default Dispatch simulated events

    Hi everyone.

    I'm trying to build an helper tool in Java for an online game. It must display some popup menus (and little else) when I press some keys while playing. A native method (which I wrote myself) correctly returns to me data about the in-game pressed keys, as an array of KeyEvents.

    Now, I need to dispatch them to my application, in a clean and safe way.

    1 - What should I set as the source of the KeyEvent? (for KeyEvent.getSource())
    2 - To what method should I pass the event? Is there a "global" method, or should I proceed component by component?
    3 - My application is always in foreground (the user is supposed to be playing the game!). Does this bring up problems?

    I tried to figure out it myself, but I'm confused by dozens of "postAwtEvent", "processAwtEvent", "dispatchAwtEvent" methods in dozens of Component classes and utility classes. And I'm concerned about the background/foregound problem as well.

    Thanks in advance!

    PS: Please, no java.awt.Robot tricks. They're not what I mean for "a clean and safe way".

  2. #2
    kusanagi97 is offline Member
    Join Date
    Oct 2009
    Rep Power


    I found out this is the correct way to dispatch an awtEvent:

    Java Code:
    However, keyboard events don't get processed if the application is not focused. Is there a way I can bypass the KeyboardFocusManager? How should I implement my own?

Similar Threads

  1. Dynamic Method Dispatch
    By sandeshforu in forum New To Java
    Replies: 0
    Last Post: 09-15-2009, 06:18 PM
  2. incompatible types...What is "Dispatch" ?
    By ollyworks in forum Java Applets
    Replies: 1
    Last Post: 09-10-2009, 04:03 AM
  3. Need Help with events
    By Gatts79 in forum AWT / Swing
    Replies: 3
    Last Post: 09-23-2008, 04:18 AM
  4. Error: Exception during event dispatch!
    By Javid in forum AWT / Swing
    Replies: 1
    Last Post: 08-02-2008, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts