PDA

View Full Version : detect enter key press


Peter_Chea
04-21-2004, 03:03 PM
Hi, I am trying detect the enter key press with no sucess. Does anyone know what I did wrong?

<canvas>
<edittext name="keyword" x="5" width="100" doesenter="true">

<method name="doEnterUp">
debug.write("doEnter");
//super.doEnterUp();
</method>
<method name="doEnterDown">
debug.write("doEnter");
//super.doEnterUp();
</method>
</edittext>
</canvas>

antun
04-22-2004, 09:21 AM
If you want to know when someone has pressed the enter key, try:


<method event="onkeydown" args="k">
Debug.write( "onkeydown sent: " + k );
if (k == 13) Debug.write( "ENTER" );
</method>


The doEnterUp/doEnterDown keys are mainly for handling keyboard focus (e.g. for writing components that you need to be able to focus to and then hit enter on).

-Antun

Peter_Chea
04-22-2004, 09:56 AM
Thanks, the onkeydown event works.
I was assuming that when I modifing the edittext field, it is focus on the edittext field and pressing enter will cause a doEnterDown method to be call.

chrislyman
10-22-2004, 10:48 AM
I'm able to get the enter key to work, but only sometimes. I have a text field and I have the onKeyDown method loaded with an equality statement, just like the above post. I also have a button that calls the same function as the onKeyDown function.

Here's the weird part. If I type at what I consider to be an everage speed and hit enter, the function I call using the onKeyDown function behaves like there's no text there at all. I played with it a bit and figured out that when hitting the enter key there's a delay from the time I stop typing until the text will be successfully passed to my function (a few hundred ms at most). When I type at the same speed and click on the button, everything works fine.

Here's a sample of what I'm doing:


<edittext width="200" id="lastName" name="lastName">
<method event="onkeydown" args="k">
if (k == 13)
tabsSearch.inputHandler(parent.lastName.text);
</method>
</edittext>

<button onclick="tabsSearch.inputHandler(lastName.text)">Submit</button>


Anybody have any ideas?

Best,
Chris

chrislyman
10-22-2004, 11:58 AM
I made a mistake, if I enter text and press the enter key the text will never be passed to the fuction. If I enter text and then move focus away from and back to the text box and press enter everything works fine.

ericb
02-15-2005, 01:35 PM
call updateText() on the text field