Results 1 to 2 of 2
Thread: Dispatch simulated events
- 10-11-2009, 07:02 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
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".
- 10-12-2009, 02:20 PM #2
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
I found out this is the correct way to dispatch an awtEvent:
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?Java Code:Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(awtEvent);
Similar Threads
-
Dynamic Method Dispatch
By sandeshforu in forum New To JavaReplies: 0Last Post: 09-15-2009, 05:18 PM -
incompatible types...What is "Dispatch" ?
By ollyworks in forum Java AppletsReplies: 1Last Post: 09-10-2009, 03:03 AM -
Need Help with events
By Gatts79 in forum AWT / SwingReplies: 3Last Post: 09-23-2008, 03:18 AM -
Error: Exception during event dispatch!
By Javid in forum AWT / SwingReplies: 1Last Post: 08-02-2008, 01:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks