Search code examples
actionscript-3apache-flexflex3

How to detect CTRL + C input and F3 key inputs in flex


I am trying to implement find functionality in my application and for this I am trying to open a find popup based on keyboard inputs like F3 or CTRL + F. But on F3, instead of going to event listener, it opens up the default find toolbar of the Internet Explorer instead. Any clues, how I could bypass it and use f3 in my application?

Another thing is how do I capture CTRL + F in flex?

private function keyPressed(evt:KeyboardEvent):void
{
    if (evt.keyCode == Keyboard.F3)
    {
        //open popup
    } else {
        //do something elese
    }
}

Thanks.


Solution

  • For detecting CTRL + F:

    event.ctrlKey == true && event.keyCode == Keyboard.F
    

    where 'event' is of course a KeyBoardEvent.

    As for the F3 question: the code you wrote will work as long as the flash application has focus. The F3 key command will then also not be routed to the browser. So what you need to do, is make sure that your application has focus when the user hits F3. How you solve this will depend on your JavaScript implementation. You could use ExternalInterface to tell the browser that the app is ready and than focus on the app. Or in Javascript you could catch the keyboard event, prevent its default behavior, and then call the function on the Flash app (again through ExternalInterface).

    To get you started, here's a little JQuery snippet for preventing the default F3 behaviour:

    $('body').keyup(function(event) {
        if (event.keyCode == '114') event.preventDefault();
    }