How do I store keys pressed

Posted by Glycerine on Stack Overflow See other posts from Stack Overflow or by Glycerine
Published on 2010-04-02T14:38:58Z Indexed on 2010/04/02 14:43 UTC
Read the original article Hit count: 367

I would like to store keys pressed when I listen out for the keyDown on the stage. I can add the listener fine, but I'm not getting the character I want out of the event to store it into a string.

This is what I have so far:

    private var _addToString:String = "";
    public function Hotwire()
    {
        this.addEventListener(KeyboardEvent.KEY_DOWN, keydownEventHandler); 
    }

    private function keydownEventHandler(ev:KeyboardEvent):void
    {
        trace("Key pressed: " + ev.charCode );

        addToString(ev.charCode);


    }

    private function addToString(value:uint):String
    {
        trace(_addToString);
        return _addToString += String.fromCharCode(value);
    }

Every key I press its returns '0'. How do I convert the chatCode to a real alphanumeric character I can read later?

Thanks in advance

© Stack Overflow or respective owner

Related posts about actionscript

Related posts about event-handling