Skip to main content
TheOriginalGC
Community Expert
Community Expert
March 8, 2025
Answered

Finding the cursor keys in Animate javascript

  • March 8, 2025
  • 1 reply
  • 622 views

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;

}
}

    Correct answer TheOriginalGC

    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?

    1 reply

    kglad
    Community Expert
    Community Expert
    March 8, 2025

    you mean the arrow keys?

    TheOriginalGC
    Community Expert
    Community Expert
    March 8, 2025

    Yes sir. 

    kglad
    Community Expert
    Community Expert
    March 8, 2025