[SOLVED] Screen Moved with Arrow Keys - How To Avoid this?

Hi there,

I have submitted one of my games to Crazy Games, but this game needs to be played with arrow keys. The problem is that when I press the arrow keys (up, down, left or right) the screen is moved too.

According to the documentation return true (inside the key listener, course) can avoid the operating system execute its default handling of the keys, but it does not works for me.

No sure w/o trying myself, but why not use WASD instead?

What is WASD?

Ok, made a simple research and I already know what is WASD. They are the W, S, A and D keys. I think that is the only solution for now. Thanks a lot!

I have found the solution.Add the next code to a javascript script:

window.addEventListener(“keydown”, function(e) {
// Arrow keys, 37, 38, 39, 40
// keyCode is deprecated
if ( [37, 38, 39, 40].indexOf(e.key) > -1 || [37, 38, 39, 40].indexOf(e.keyCode) > -1 ) {
e.preventDefault();
}
}, false);

2 Likes