Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-04-2012, 07:48 PM   PM User | #1
bon_t
New Coder

 
Join Date: Jul 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
bon_t is an unknown quantity at this point
Issue with capturing shortcut keys

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
bon_t is offline   Reply With Quote
Reply

Bookmarks

Tags
key event, shortcut key

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:12 AM.


Advertisement
Log in to turn off these ads.