Triggering FlexSpy with a Keyboard Shortcut

On September 5, 2009, in AIR, Flex, by Anuj Gakhar

If you are a Flex developer, you are probably aware of what FlexSpy is. FlexSpy is an inspection tool for Flex applications, similar to what Firebug is for HTML applications. FlexSpy is distributed as a .swc file (Flex Library file) which you can simply put under your projects’ “libs” folder and it will become available to use in your project. Once you trigger FlexSpy , you can inspect and change the properties and styles of the visual components in your Flex application. Pretty useful tool, makes life very easy for a developer.

All the examples I have seen so far, there is either a Button or some kind of visual element to bring up the FlexSpy window from within your application. However, I realize, that is not always desired. I normally associate a keyboard shortcut for this very purpose. So, I as a developer can bring it up when I want and no one notices that its there.

The code for this looks like this :-

<mx:Script>
 <![CDATA[
 import com.flexspy.FlexSpy;

 private function init():void{
 this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
 }

 private function onKeyUp(e:KeyboardEvent):void
 {
 if(e.ctrlKey && e.shiftKey && e.keyCode == 188)
 {
    FlexSpy.show();
 }
 }
 ]]>
 </mx:Script>

What this code does is, you press CTR+SHIFT+COMMA together, FlexSpy window shows up. You can choose whatever key combination you want. However, do note that I had to hardcode the value 188 for comma key. If you want to find which key has which keyCode , simply do a trace(e.keyCode) in your handler function.

For some reason, if you are doing this in a Flex Project, the Keyboard class does not contain all your keyboards’ keys. But if you are in an AIR project, you could have written the same code like below:-


<mx:Script>
 <![CDATA[
 import com.flexspy.FlexSpy;

 private function init():void{
 this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
 }

 private function onKeyUp(e:KeyboardEvent):void
 {
 if(e.ctrlKey && e.shiftKey && e.keyCode == Keyboard.COMMA)
 {
   FlexSpy.show();
 }
 }
 ]]>
 </mx:Script>

Note, how Keyboard class shows up all the keyboards’ keys . In this case, Keyboard.COMMA. I am not sure why these particular keys are “AIR only” though.

Tagged with:  

One Response to Triggering FlexSpy with a Keyboard Shortcut

  1. nico says:

    instead of “e.keyCode == 188” you can use “e.charCode == “,”.charCodeAt(0)”.

    It is self documenting.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 445 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: