0

I have this code :

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

Unfortunaly looking at https://apache.github.io/royale-docs/component-sets/jewel/textinput I didn't find a bead for KeyDown event. Is there a specific event to listen for it ?

Is there a way to know if enter key has been hit ?

Thanks Regards

Fred
  • 399
  • 3
  • 12

2 Answers2

1

I must say that there's a better solution to your problem, but I completely forgot due to focus on keydown. Sorry.

You have an enter event in TextInput that you can use directly. Example is in Tour De Jewel in TextInputPlayGround.

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

HTH

Carlos

Carlos Rovira
  • 507
  • 2
  • 11
  • Thanks, effectively that's better ! Note on your previous post (which is also very interessing), it's event.type to be tested for 'KeyDown' (not event.key) – Fred May 28 '20 at 12:25
  • Right, I was confused and thinking you were referring to "arrow down key" ;) – Carlos Rovira May 28 '20 at 14:15
0

you need to listen for KeyboardEvent.KEY_DOWN on the strand (TextInput).

If you are in MXML, first add a listener for initComplete in the surrounding container for listenKeyDown:

initComplete="listenKeyDown()"

Then in the Script part add:

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 Rovira
  • 507
  • 2
  • 11
  • Thanks Carlos, I little fix code to done it working. – Fred May 28 '20 at 08:13
  • More over, does I need take care of using removeEventlistener ? (I will open a new SOF on it) – Fred May 28 '20 at 08:14
  • you need to remove listeners as usual. If you adding/removing components that are listening to other parts of the app, be sure to maintain the listeners to avoid leaks – Carlos Rovira May 28 '20 at 11:04