Adobe Flex

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentAdobe Flex

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old January 4th, 2012, 01:07 PM
bon_t bon_t is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2010
Posts: 25 bon_t User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 51 m 26 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentAdobe Flex > Issue with capturing shortcut keys


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap