tefozi
tefozi

Reputation: 5480

Capture hotkey in browsers

I'm doing SWF application which will run in browser. And I want to capture CTRL+F key pressing event when Flex application is in focus.

In Firefox it works fine but in Opera and Safari browser captures event prior to Flex application and Find Dialog pop-ups.

Is there any way for flex application to capture CTRL+F event prior browser?

Upvotes: 7

Views: 1433

Answers (3)

Lance Pollard
Lance Pollard

Reputation: 79248

I asked this same question recently and have been playing around with it.

I came up with this gist on github:

Browser KeyboardEvent Hijacking with Javascript and Flex

CTRL-F works!

Check out the javascript in there. Basically, with Safari, you can only hear the meta keys (ctrl/alt/shift, etc.); it won't allow javascript to hear A-Z events if Flash is running for some reason. So I just listen for the meta keys in javascript, and then call window.focus() in javascript. That sets focus to the browser, making it so you can hijack browser keyboard events!. Then I listen for the A-Z events or whatever, and pass those to Flex.

The next step is to just restore focus in your Flex app to wherever it was before that, which should be easy.

Cheers, Lance

Upvotes: 2

Scott
Scott

Reputation: 11186

Where e is a keyboard event:

if(e.commandKey || e.ctrlKey){

    switch(e.keyCode){
        case Keyboard.N:
            // do stuff
            break;
    }
}

Upvotes: 0

invertedSpear
invertedSpear

Reputation: 11054

Maybe add javascript to your html containing the swf that would block it. It sounds like those browsers process events in a different order so I doubt there would be anything you can do from within the flash player that would do it.

Upvotes: 0

Related Questions