What's the best way to handle keyboard events?

Daniel's Avatar


28 Jan, 2010 01:21 AM

I've started crawling on my robotlegs =)

So, I thought to create a command called Keypress and so I added

commandMap.mapEvent( KeyboardEvent.KEY_DOWN, Keypress );

Do I need to then listen for the keydown event in my application (mxml) and then dispatch a new system/custom event?

  1. 1 Posted by Daniel on 28 Jan, 2010 01:48 AM

    Daniel's Avatar

    I didn't realize that only members of the RL framework can dispatch events.

    What I ended up doing was
    1) map an application mediator to my application file
    2) map a command to the keyboard keydown event
    3) in the mediator map a listener for keyboard key down event
    4) dispatch that event to the framework

    It works. Are there other ways?

  2. Support Staff 2 Posted by Joel Hooks on 28 Jan, 2010 01:53 AM

    Joel Hooks's Avatar

    Your approach is perfectly acceptable (and likely how I would do it)

    I wanted to say that it isn't true that only framework classes can dispatch events to the framework. All of the framework actors are injected with a context scoped IEventDispatcher that is used to talk within a context. In practice that IEventDispatcher can be a variable on any object without regard to its status in the framework. That said, it is better to encapsulate that communication in the maneer that you outlined and not have your components speaking across the application layer.

  3. 3 Posted by Daniel on 28 Jan, 2010 04:54 AM

    Daniel's Avatar

    Great! That's good to know about the IEventDispatcher though. Could potentially save some time upfront for refactoring later.

  4. Joel Hooks closed this discussion on 28 Jan, 2010 04:56 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac