Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By the way, the workaround I'm currently favoring is to discard additional key down events for a key during a brief dead-band (maybe 50-100 ms) following its initial key down event. This solution has the merits of being relatively simple to implement while still supporting key repeats, though with an additional delay before repeat begins.</p> <p>Here's basically what I've added to the test code:</p> <pre><code>private var keyDownTs:Array = new Array(); private function onKey(event:KeyboardEvent):void { var msg:Label = new Label(); msg.text = getTimer() + "-" + (isDead(event) ? "**DEAD**" : "") + event.toString(); eventLog.addChildAt(msg, 0); } private function isDead(event:KeyboardEvent):Boolean { var dead:Boolean = false; switch (event.type) { case KeyboardEvent.KEY_DOWN: var ts:int = keyDownTs[event.keyCode]; if (ts == 0) { // save timestamp for the initial key down event keyDownTs[event.keyCode] = getTimer(); } else if (getTimer() - ts &lt; 50) { // this key down is within the dead-band of the initial key down dead = true; } break; case KeyboardEvent.KEY_UP: // clear previous key down timestamp keyDownTs[event.keyCode] = 0; break; } return dead; } </code></pre> <p>On my system, the spurious key down events are happening within a few ms of the initial key down (2-6 ms), so 50 ms is looking like a pretty good value. For my production implementation, I think I'm going to put this logic into an EventDispatcher that KeyboardEvent listeners will use instead of listening to the stage directly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload