Friday, April 2, 2010

How to hook delete and backspace key...

Hello all,

So I know I can addEventListener(TextEvent.TEXT_INPUT, onTextInput); to capture any text input events.

How do I capture when someone presses the delete or backspace key?

I have tried addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); with if(event.keyCode == Keyboard.BACKSPACE), but this triggers the event before the change is made to the text area.?Id like to capture the backspace event after the text area is updated.

Any help appreciated.

Also, does anyone know how do you capture cut / copy / paste events?

Thanks

Scott

http://www.resultswebdesign.com.au/

How to hook delete and backspace key...

Hi there

Listen for the KeyUp instead, then the event will fire after the change

%26lt;?xml version=''1.0'' encoding=''utf-8''?%26gt;
%26lt;mx:Application xmlns:mx=''http://www.adobe.com/2006/mxml'' layout=''absolute''%26gt;
?%26lt;mx:Script%26gt;
?%26lt;![CDATA[
?import mx.controls.Alert;
?
?private function keyHandler(event:KeyboardEvent):void {
?if (event.keyCode == Keyboard.BACKSPACE) {
?Alert.show('detect')
?}
?}
?]]%26gt;
?%26lt;/mx:Script%26gt;
?
?%26lt;mx:TextArea id=''ta'' x=''433'' y=''138'' width=''205'' height=''87'' keyUp=''keyHandler(event)''/%26gt;
?
%26lt;/mx:Application%26gt;

Hope that helps

Andrew

How to hook delete and backspace key...

Thanks a lot for your detailed example, I should have mentioned in my earlier post though the problem with using onkeyup... it gives a latent effect especially if the user is a heavy key presser (ie - holds down the key for a long time). I need to make the change as soon as the text is changed.

In most languages there are usually 3 events:

KeyDown, KeyPress, and KeyUp.

I could do what I want if there was a KeyPress event I could listen to...

No comments:

Post a Comment