Keyboard shortcuts for Flex UI components


ALT + A = 197
ALT + B = 166
ALT + C = 199
---
A = 65
B = 66
C = 67


Happy coding... - id: 5739 author: jorge author_email: [email protected] author_url: http://jgutierrez.wordpress.com/ date: ‘2009-08-07 01:09:14 +0530’ date_gmt: ‘2009-08-06 20:09:14 +0530’ content: “thank for the script ;) \r\nI use the script of zied and work correctly” - id: 7350 author: Prasad author_email: [email protected] author_url: ‘’ date: ‘2010-02-22 14:44:00 +0530’ date_gmt: ‘2010-02-22 09:14:00 +0530’ content: “Hi,\r\n Ihave tried the ZIED code, Its not working. Can any one help me. My Sample Code attached.\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n” - id: 7353 author: perjabs author_email: [email protected] author_url: ‘’ date: ‘2010-02-24 18:07:00 +0530’ date_gmt: ‘2010-02-24 12:37:00 +0530’ content: “Hi, I am Prasad, I am trying to implement your code, But the CTRL F & CTRL S is not triggering. Code below and Let me know your feedback. I am Using sdk 3.3 & flash player 10.\r\n\r\n\r\n\r\n\r\n\r\n\t\r\n\t\r\n\t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\r\n\r\n\r\n\t\r\n\r\n\t\r\n\r\n” - id: 7488 author: Rameshkaveti9 author_email: [email protected] author_url: ‘’ date: ‘2010-11-08 17:05:00 +0530’ date_gmt: ‘2010-11-08 11:35:00 +0530’ content: “Hello,\r\n i tried this one but it’s not getting the out put plz help me here is my code\r\n\r\nvar bCTRLPressed:Boolean = event.altKey;\r\n\t\t\t\r\n\r\n\t\t\tif( bCTRLPressed)\r\n\t\t\t{\r\n\t\t\t\r\n\t\t\t\r\n\t\t\tvar curKeyCode:int = event.keyCode;\r\n\t\t\t\r\n\t\t\t\r\n\t\t\tif(curKeyCode==78)\r\n\t\t\t{\r\n\t\t\t\r\n\t\t\tModuleload(‘fooditem’,1);\r\n\t\t\t\t\t\t\r\n\t\t\t\r\n\t\t\t}\r\nI am using Flex3 and flashplayer 10 “ ---

Again someone on flexcoders wanted to assign keyboard shortcuts for UI components/controls in his application. Following was my response with quick and dirty example..
Suppose you want to assign some keyboard shortcuts to each
control on screen so that when shortcut key is pressed, control gets
focussed and pressing enter/space execute associated action. For example, pressing space key while a button is focussed, would be broadcast button’s click event.
You can easily achieve this by using Key object, as demonstrated in code later.
I am assuming:


Following example has some controls on screen and pressing CTRL + 1 .. CTRL\

###KeyObjectDemo.mxml###

var keyListener:Object; function debugTrace(msg) { _ta.text+= msg + newline; } function initApp() { keyListener = new Object(); keyListener.onKeyDown = mx.utils.Delegate.create(this, mx.utils.Delegate.create(this,shorcutHandler)); Key.addListener(keyListener); } function shorcutHandler() { var bControlPressed:Boolean = Key.isDown(Key.CONTROL); if(bControlPressed) { //CTRL if(Key.isDown(49)) { // 1 debugTrace("CTRL + 1"); //set focus to textfield my_input.setFocus(); }else if(Key.isDown(50)) { //2 debugTrace("CTRL + 2"); //set focus to button my_btn.setFocus(); }else if(Key.isDown(51)) { //3 debugTrace("CTRL + 3"); my_radio.setFocus(); }else if(Key.isDown(52)) { //4 debugTrace("CTRL + 4"); my_check.setFocus(); }else if(Key.isDown(53)) { //5 debugTrace("CTRL + 5"); my_combo.setFocus(); } } } mx:Script> Indiamx:String> USAmx:String> Australiamx:String> mx:Array> mx:dataProvider> mx:ComboBox> mx:VBox> mx:Application>