Two and three key sequences

 

                  private var _escIsDown:Boolean=false;

                  private var _f1IsDown:Boolean=false;

                  private var _f2IsDown:Boolean=false;

                  private var _f4IsDown:Boolean=false;

 

                  private function
onKeyStrokeEvent(event:KeyboardEvent):void {

                        if(event.keyCode==Keyboard.ESCAPE) {

                              this._escIsDown = (event.type ==
KeyboardEvent.KEY_DOWN);

                        }

                        if(event.keyCode==Keyboard.F1) {

                              this._f1IsDown = (event.type ==
KeyboardEvent.KEY_DOWN);

                        }

                        if(event.keyCode==Keyboard.F2) {

                              this._f2IsDown = (event.type ==
KeyboardEvent.KEY_DOWN);

                        }

                        if(event.keyCode==Keyboard.F4) {

                              this._f4IsDown = (event.type ==
KeyboardEvent.KEY_DOWN);

                        }

                        if(this._escIsDown && this._f1IsDown &&
this._f4IsDown ){

                              this.panicFunction();

                        }

                        if(this._escIsDown && this._f2IsDown ){

                              this.callHome();

                        }

                  }

                  

                  /**

                   *  place code in this function to be executed by
client when instructed by support.

                   * */

                  private function callHome():void {

                        DoSomething();

                        trace("CALL HOME FUNCTION CALLED: ");

                  }

 

                  /**

                   *  place code in this function to be executed by
client when instructed by support.

                   * */

                  private function panicFunction():void {

                        DoSomethingElse();

                        trace("PANIC FUNCTION CALLED: ");

                  }

 

From: [email protected] [mailto:[email protected]] On
Behalf Of mookie298347
Sent: Tuesday, December 16, 2008 10:47 AM
To: [email protected]
Subject: [flexcoders] Pattern for capturing multi-key/click actions?

 

I would like to add multi-key/click functionality to my Flex app.
There are a couple of slightly different examples of what I mean:

1. Detect when a user is holding down the 'r' key while clicking a
button.

2. Detect when a certain component has focus and the user types the
letters 'd' 's' in succession within a few seconds of each other.

I noticed there are properties in the MouseEvent class to detect
things like shift,ctrl and alt keys but I need to detect more than
just those. Additionally those properties don't exist in other event
classes like ItemClickEvent.

What I have done so far is simply create a state object at the
application level that captures all keyboard/mouse events and sets the
state of itself based on the events. Individual components can check
the current state at any time to determine which keys/mouse actions
are currently active. 

I don't particularly like this implementation for many reasons and was
hoping someone knew of a pattern to use considering many applications
support such functionality (Eclipse comes to mind).

Thanks!

 

<<image001.jpg>>

<<image002.jpg>>

Reply via email to