【问题标题】:Apache Royale : How to detect enter key on j:textInputApache Royale:如何检测 j:textInput 上的输入键
【发布时间】:2020-05-26 17:04:05
【问题描述】:

我有这个代码:

<j:TextInput localId="ti_pass"  >
    <j:beads><j:PasswordInput/></j:beads>
</j:TextInput>

不幸地看着https://apache.github.io/royale-docs/component-sets/jewel/textinput我没有找到KeyDown事件的珠子。 是否有特定的事件来监听它?

有没有办法知道是否按下了回车键?

感谢问候

【问题讨论】:

    标签: keyboard-events textinput apache-royale


    【解决方案1】:

    我必须说有更好的解决方案可以解决您的问题,但由于专注于 keydown,我完全忘记了。对不起。

    您在 TextInput 中有一个 enter 事件,您可以直接使用它。示例在 TextInputPlayGround 的 Tour De Jewel 中。

    private function enterPress(event:Event):void
    {
        trace("enter pressed");
    }
    
    <j:TextInput text="A TextInput" enter="enterPress(event)"/>
    

    HTH

    卡洛斯

    【讨论】:

    • 谢谢,这样更好!注意你之前的帖子(这也很有趣),它是 event.type 来测试'KeyDown'(不是 event.key)
    • 对,我很困惑,以为您指的是“向下箭头键”;)
    【解决方案2】:

    您需要在链 (TextInput) 上收听 KeyboardEvent.KEY_DOWN

    如果你在 MXML 中,首先在 listenKeyDown 的周围容器中添加一个 initComplete 的侦听器:

    initComplete="listenKeyDown()"
    

    然后在Script部分添加:

    public function listenKeyDown():void {
        the_textinput.addEventListener(KeyboardEvent.KEY_DOWN, keyDownEventHandler)
    }
    
    protected function keyDownEventHandler(event:KeyboardEvent):void
    {
        trace("Any key:", event.key);
    
        if(event.key === KeyboardEvent.KEYCODE__DOWN)
        {
            trace("Down key:", event.key);
        }
    }
    

    【讨论】:

    • 感谢 Carlos,我几乎没有修复代码来完成它。
    • 此外,我需要注意使用 removeEventlistener 吗? (我会在上面开一个新的 SOF)
    • 你需要像往常一样删除监听器。如果您添加/删除正在侦听应用程序其他部分的组件,请务必维护侦听器以避免泄漏
    猜你喜欢
    • 2012-09-10
    • 2017-03-29
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    • 1970-01-01
    • 2014-04-18
    相关资源
    最近更新 更多