Skip to main content
TheOriginalGC
Community Expert
Community Expert
Mar 8, 2025 5:16 PM UTC
Answered

Finding the cursor keys in Animate javascript

I've searched  the forums for an answer but can't find what I'm looking for. I'm trying to convert some AS3 code to javaScript and I can't figure out the syntax for the left and right cursor keys. This is what I've got in AS3:

 

function keyDownFunction(event : KeyboardEvent) : void
{

if (event.keyCode == 39)
{
walkerSpeed = walkerSpeed+1;
}
if (event.keyCode == 37)
{
walkerSpeed = walkerSpeed-1;

}
}

    TheOriginalGC
    TheOriginalGCCorrect answer
    Community Expert
    Mar 8, 2025 10:25 PM UTC

    what listener are you using?


    Funny thing about that. I'm using

    document.onkeydown = checkKey;
    function checkKey(e) {
    e = e || window.event;

    //etc.

    }

    And it works. Who knew?

    9 replies

    kglad
    Community Expert
    Community Expert
    Mar 8, 2025 6:40 PM UTC

    you mean the arrow keys?

    Translate
    TheOriginalGC
    Community Expert
    Community Expert
    Mar 8, 2025 7:54 PM UTC

    Yes sir. 

    Translate
    kglad
    Community Expert
    Community Expert
    Mar 8, 2025 8:09 PM UTC