tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/354-what-is-the-best-way-to-listen-for-key-eventsRobotlegs: Discussion 2013-04-28T09:54:56Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/89099002011-07-27T20:36:07Z2011-07-27T20:36:07Zwhat is the best way to listen for key events<div><p>You should use <code>evt.preventDefault()</code> to prevent the
app from closing at Back button and you're using it. Please try to
do the same without any command mapping for a check. Just
addEventListener and in handler method use
<code>preventDefault()</code>, remove
<code>evt.stopImmediatePropagation();</code> by the way.</p>
<p>And what is
<code>contextView.stage.addEventListener(KeyboardEvent.KEY_DOWN,
dispatchEvent);</code> doing? Maybe dispatchEvent handler stops
immediate propagation?</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/89099002011-07-27T20:52:55Z2011-07-27T20:52:58Zwhat is the best way to listen for key events<div><p>Hi michal<br>
I have tried as without command and it works but this my
implementation above does not work. So this leads me to believe
that I need to do this differently as I think the preventdefault()
is not working the way it is. Is there a different way to do the
above so the event is passed directly to the function. Any code
will help.</p>
<p>Regards mike :)</p></div>Mike oscartag:robotlegs.tenderapp.com,2009-10-18:Comment/89099002011-07-28T10:37:08Z2011-07-28T10:37:08Zwhat is the best way to listen for key events<div><p>Looks like not the same instance of the event is passed to the
command or something else causes the problem. Do it that way:<br>
1. Leave listener without the command. It will prevent the default
behavior. Don't use stopImmediatePropagation(). 2. Use your own
logic as you described in your command. You don't have to
preventDefault here.</p>
<p>Please debug your application and place breakpoints in both
command and key listener. Check if events are the same instances
(compare memory pointers)</p>
<p>Thanks<br>
Mike</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/89099002011-07-28T10:44:27Z2011-07-28T10:44:27Zwhat is the best way to listen for key events<div><p>The clone() will mean that the events are unlikely to be the
same instances.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/89099002011-07-28T10:45:13Z2011-07-28T10:45:13Zwhat is the best way to listen for key events<div><p>When events are cloned?</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/89099002011-07-29T21:46:59Z2011-07-29T21:47:02Zwhat is the best way to listen for key events<div><p>Why would RL clone the event? Can't it just pass along the
original reference to the command?</p></div>Shawntag:robotlegs.tenderapp.com,2009-10-18:Comment/89099002011-07-29T21:57:33Z2011-07-29T21:57:33Zwhat is the best way to listen for key events<div><p>Shawn, no idea.</p>
<p>I'm using SignalCommandMap and if I need to pass an event I just
pass it there :) So I haven't faced the problem. Thanks for letting
us know. Probably it should be filled as a bug.</p>
<p>Mike</p></div>Michal Wroblewskitag:robotlegs.tenderapp.com,2009-10-18:Comment/89099002011-09-14T19:25:30Z2011-09-14T19:25:30Zwhat is the best way to listen for key events<div><p>If you redispatch an Event, EventDispatcher automatically clones
it, because the Event's target and currentTarget properties could
be different.</p></div>Robert Penner