Hi,

In response to your puzzle, the following code will simulate a button click when CTRL-Z is pressed and released.  However, this code doesn't seem to work for the KEY_DOWN keyboard event.  It may be a bug, but the ctrlKey Boolean doesn't want to remain TRUE when the CNTRL modifier key is held down and another key is pressed (only released).

If you use this technique in multiple components, I think that you'll run into eventListener overlap.  But, if you use it sparingly, it could come in handy.

Best Wishes,
Tim Hoff

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" creationComplete="addListeners();">

    <mx:Script>
    <![CDATA[

             import flash.events.Event;
             import flash.events.KeyboardEvent;
             import flash.events.MouseEvent;
             import mx.core.Application;
             import mx.controls.Alert;

  
             private function addListeners():void
             {
                  Application.application.addEventListener(KeyboardEvent.KEY_UP, trapKeys);
             }

             private function trapKeys(e:KeyboardEvent):void
             {
                  if (e.charCode==122 && e.ctrlKey == true) // Z key + CTRL key    
                  {
                       button1.dispatchEvent(new MouseEvent(MouseEvent.CLICK,false,false));
                  }
             }

             private function buttonClickHandler():void
             {
                  Alert.show("The button was clicked");
             }
  
      ]]>
      </mx:Script>

      <mx:Button id="button1" label="Click me first to give the application focus.  Then press CTRL-Z to simulate the click."  click="buttonClickHandler();"/>

</mx:Application>


--- In flexcoders@yahoogroups.com, "shemeshkale" <[EMAIL PROTECTED]> wrote:
>
> hi,
> i want that when a certain keyboard is pressed some of the components
> event will fire.
> i want do to this in keyDown.
>
> for example, here when the user clicks control+z i want to fire the
> buttons click event. (remap ctrl+z to be a click)
> <mx:Button keyDown="if(event.crtlKey==true && event.code==90)click;"
> label="press here" />
>
> HOW?
>



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to