views:

141

answers:

2

Hi,

In my flex application, I would like to know the edit mode of insert key programmatically. In the status bar of the application there should be an indicator for the mode in which currently working. As the insert key is toggle key, how can i know the mode of it?

Thanks in advance.

A: 

You can record the keys being pressed with a KeyboardEvent.KEY_DOWN and KeyboardEvent.KEY_UP. You have to add these to the stage on application complete or they will not work.

<mx:Application applicationComplete="ApplicationComplete()" etc...

And then have a function:

    public function ApplicationComplete():void {
 stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown);
 stage.addEventListener(KeyboardEvent.KEY_UP, KeyUp);  
}

And then the event functions:

    public function KeyDown(e:KeyboardEvent):void {
        if (e.keyCode = whateverTheInsertKeyCodeIs) {
                   isInsertPressed = true;
            }
}
public function KeyUp(e:KeyboardEvent):void {
 if (e.keyCode = whateverTheInsertKeyCodeIs) {
                   isInsertPressed = false;
            }
}

Or if you're using it as a toggle:

    public function KeyDown(e:KeyboardEvent):void {
        if (e.keyCode = whateverTheInsertKeyCodeIs) {
                   insertToggle = !insertToggle;
            }
}

I hope this helps!

Jesse
A: 

GREAT ANSWER JESSE !