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.
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>