Skip to main content
Participating Frequently
July 11, 2009
Answered

event handler problems

  • July 11, 2009
  • 1 reply
  • 401 views

Hi,


I'm having problems with a event handler that I'm trying to create.

I currently have 2 event handlers, one of which needs to only happen when Shift + a key is pressed. I currently have:

function keypressedHandler(event:KeyboardEvent):void {
     if ((event.shiftKey) + (event.keyCode == 81)) {

       //something would happen

     }

}


So my question is how can I get the shift function to work? It doesn't matter if it isn't shift but Alt or Ctrl would be the alternatives.

Any help would be great,

Thanks,

This topic has been closed for replies.
Correct answer Manno_Bult-to3djt

You need the ampersand (&) instead of the plus sign to use the logical AND:

stage.addEventListener( KeyboardEvent.KEY_DOWN, keypressedHandler )

function keypressedHandler(event:KeyboardEvent):void
{     
    if ((event.shiftKey) && (event.keyCode == 65))
    {      

        //something would happen     
        trace( "shift and 65" )
    }
}

1 reply

Manno_Bult-to3djtCorrect answer
Inspiring
July 11, 2009

You need the ampersand (&) instead of the plus sign to use the logical AND:

stage.addEventListener( KeyboardEvent.KEY_DOWN, keypressedHandler )

function keypressedHandler(event:KeyboardEvent):void
{     
    if ((event.shiftKey) && (event.keyCode == 65))
    {      

        //something would happen     
        trace( "shift and 65" )
    }
}

Participating Frequently
July 11, 2009

Thanks for that. I really should have tried changing the ++ to &&!