Hi All,

I am using Adobe Flash Builder 4.0.1.

In my application, there is a module that allows a user to listen to an audio file and transcribe what he hears. We have the following two shortcut keys (among others): Ctrl + Space to play the audio file and Ctrl + Enter to save the transcription.

Two components of this module are TranscriptionText.mxml (creates the Editor window in which to type the transcription) and ShortCutKeyDispatcher.as (which is misleading; it doesn't dispatch the shortcut key event, it actually handles it).

In ShortCutKeyDispatch.as, there's the following code:

Code:
public function registerTranscription(transcription:TextArea):void  
{
     if (_transcription != null || transcription == null)
          throw createUsageError();
     log("Register text area");
     _transcription = transcription;
     FlexGlobals.topLevelApplication.addEventListener(K  eyboardEvent.KEY_UP, keyHandler);
}
Code:
private function keyHandler(event:KeyboardEvent):void
{
     if (GlobalProperties.INSTANCE.formId != formId)
          return;
     log("Handle key " + event.keyCode);
     var bCtrlPressed:Boolean = event.ctrlKey;
     var bShiftPressed:Boolean = event.shiftKey;
     var curCharCode:int = event.charCode; 
               
     if ( bCtrlPressed && bShiftPressed )
     {
          switch ( curCharCode )
          {
               case 40:  // 40 is the charcode value for '('
                    transcription.insertText("[g] ");
                    break;
               case 41:  // 41 is the charcode value for ')'
                    transcription.insertText("[q] ");
                    break;
          }
     }
     else if (bShiftPressed)
     {
          switch ( curCharCode )
          {
               case 32:  // 32 is the charcode value for Space
                    // Reset audio position to beginning
                    removeLastCharFromTranscript( curCharCode );
                    setTrackPosition(0);
                    break;
          }
     }
     else if (bCtrlPressed)
     {                    
          switch (curCharCode)
          {
               case 13:  // 13 is the charcode value for Enter/Return
                    // Send current transcription (Save)
                    removeLastCharFromTranscript( curCharCode );
                    saveTranscription();
                    break;
               case 32:  // 32 is the charcode value for Space
                    removeLastCharFromTranscript( curCharCode );
                    if (playing())
                         pauseAudio();
                    else
                         playAudio();
                    break;
               case 44:  // 122 is the charcode value for ','
                    rewind();
                    break;
               case 46:  // 120 is the charcode value for '.'
                    fastForward();
                    break;
               case 91:  // 91 is the charcode for '['
                    changeValueByStep(false); // decrease the audio volume
                    break;
               case 93:  // 93 is the charcode for ']'
                    changeValueByStep(true); // increase the audio volume
                    break;
               case 59:  //  59 is the charcode value for ';'
                    transcription.insertText("[n] ");
                    transcription.dispatchEvent(new TextOperationEvent(Event.CHANGE));
                    break;
               case 39:  //  39 is the charcode value for '''
                    transcription.insertText("[c] ");
                    transcription.dispatchEvent(new TextOperationEvent(Event.CHANGE));
                    break;
               case 47:  // 47 is the charcode value for forward slash
                    transcription.insertText("[u] ");
                    transcription.dispatchEvent(new TextOperationEvent(Event.CHANGE));
                    break;
          }
     }
}
The issue is that, when the two keys (Ctrl + Space or Enter ) are pressed very quickly (as should be expected), the expected action is not performed. To debug, I put a breakpoint at the beginning of the keyHandler logic above. When the app stopped at the breakpoint, I see that event.ctrlKey = false and event.charCode = 0 (not event.ctrlKey = true and event.charCode = 13 or 32)! I ran the app and it stopped at the breakpoint again (I wasn't expecting this). This time, however, event.ctrlKey = false still BUT event.charCode = 13 or 32. Every now and then, the app stopped at the breakpoint a third time, and this time event.ctrlKey = true.

So I am confused. The code is detecting the "key pressed" event, but there seems to be a delay in the pertinent values being updated. If we hold down the Ctrl key a little longer, and then press and hold down a little longer the Space or Enter key, then it works about 90% of the time.

Your help is greatly appreciated!
Bon :-D