Reputation: 2983
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.
Upvotes: 3
Views: 3090
Reputation: 14344
This is in response to your second question, which by the way, should probably be asked in a completely separate question.
This solution will allow you to test for as many key combinations as you need. It stores the pressed keys in an array and tests agains the array to determine combinations.
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class MultiKeyHandlerApp extends Sprite
{
protected var keyCodes:Array;
public function MultiKeyHandlerApp()
{
keyCodes = [];
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownHandler );
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUpHandler );
}
protected function onKeyDownHandler( event:KeyboardEvent ):void
{
addKey( event.keyCode );
// -- 65 = a, 83 = s, 68 = d
if( hasKey( 65 ) && hasKey( 83 ) && hasKey( 68 ) )
{
trace( "match!" );
}
}
protected function onKeyUpHandler( event:KeyboardEvent ):void
{
removeKey( event.keyCode );
}
protected function addKey( keyCode:int ):void
{
if( keyCodes.indexOf( keyCode ) < 0 ) keyCodes.push( keyCode );
}
protected function removeKey( keyCode:int ):void
{
var index:int = keyCodes.indexOf( keyCode );
if( index > -1 ) keyCodes.splice( index, 1 );
}
protected function hasKey( keyCode:int ):Boolean
{
return keyCodes.indexOf( keyCode ) >= 0;
}
}
}
Upvotes: 1
Reputation: 11912
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();
}
Upvotes: 4
Reputation: 2238
Just checked on all of the browsers ( all are up to date ). with 10.3 flash player.
Everything is working on Chrome / FireFox / Opera. The main thing you need to do is to make sure you have the focus on the flash movie ( swf ), but not on the browser ( HTML ) or somehwere else.
Since IE is using the ActiveX technology, it catches all of the Function keys event to it self first, and then parsing it to the Flash.
Same thing on safari.
But you can use F2, F8 and F9 on All browsers.
And for getting the combination of ctrl / alt / shift.
KeyboardEvent has some nice properties: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/KeyboardEvent.html#propertySummary
Upvotes: 0