could someone check over this snippet of javascript please

Associate
Joined
11 Oct 2008
Posts
268
Hey guys, I have this bit of javascript which loads a certain url if the w,a,s,d keys are pressed. Its working fine but a lot of examples I've been looking at include things like break; and addeventlistener.

Mine does not include these things so I just wanted to check my code isn't incomplete or flawed. Thanks guys.

Code:
 <script>
    document.onkeydown = function(e) {
    e = e || window.event;
    key = e.keyCode || e.charCode;
    var keys = { 
      87: '?move=up', 
      68: '?move=right', 
      83: ?move=down', 
      65: '?move=left'
    };
    if (keys[key]) window.location.href = keys[key];
    };
    </script>
 
Associate
OP
Joined
11 Oct 2008
Posts
268
Okay, Sorry to be a pain, how would I implement it into my bit of code.
I know next to nothing with javascript so have been trying a few different ways but they all seem to break the code. Firefoxs debugger isn't showing me any error messages either so I'm at a loss.

Thanks again for all your help.
 
Back
Top Bottom