如何检测 CTRL + Flex 中的 C 输入和 F3 键输入

发布于 2024-11-19 20:05:15 字数 389 浏览 2 评论 0原文

我正在尝试在我的应用程序中实现查找功能,为此我正在尝试基于 F3 或 CTRL + F 等键盘输入打开查找弹出窗口。但是在 F3 上,它不会转到事件侦听器,而是打开默认的查找工具栏而是使用 Internet Explorer。有什么线索,我如何绕过它并在我的应用程序中使用 f3 ?

另一件事是如何在 Flex 中捕获 CTRL + F?

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

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

指尖微凉心微凉 2024-11-26 20:05:15

用于检测 CTRL + F:

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

其中“事件”当然是 KeyBoardEvent。

至于F3问题:只要Flash应用程序具有焦点,您编写的代码就可以工作。 F3 键命令也不会被路由到浏览器。因此,您需要做的是确保当用户按 F3 时您的应用程序获得焦点。如何解决这个问题取决于您的 JavaScript 实现。
您可以使用ExternalInterface 告诉浏览器应用程序已准备就绪,然后将注意力集中在应用程序上。或者在 Javascript 中,您可以捕获键盘事件,阻止其默认行为,然后调用 Flash 应用程序上的函数(再次通过ExternalInterface)。

为了帮助您入门,这里有一个用于防止默认 F3 行为的 JQuery 片段:

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

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();
}
寄意 2024-11-26 20:05:15

这是对你的第二个问题的回应,顺便说一句,这个问题可能应该在一个完全独立的问题中提出。

该解决方案将允许您测试所需数量的按键组合。它将按下的键存储在数组中,并再次测试该数组以确定组合。

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;
        }
    }
}

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;
        }
    }
}
冰雪梦之恋 2024-11-26 20:05:15

刚刚检查了所有浏览器(所有浏览器都是最新的)。带有 10.3 flash 播放器。

Chrome / FireFox / Opera 上一切正常。您需要做的主要事情是确保您的注意力集中在 Flash 影片 ( swf ) 上,而不是浏览器 ( HTML ) 或其他地方。

由于IE使用了ActiveX技术,它首先捕获所有的功能键事件给自己,然后解析到Flash中。

野生动物园也是如此。

但您可以在所有浏览器上使用 F2、F8 和 F9。

并获得 ctrl / alt / shift 的组合。

KeyboardEvent 有一些很好的属性:
http://livedocs.adobe.com/flash/9.0 /ActionScriptLangRefV3/flash/events/KeyboardEvent.html#propertySummary

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文