When I hold/press the w key on my keyboard, the whole page should scroll up. When I press the d key, it scrolls down. Except when I am in an input field, because otherwise I would scroll up/down when I want to enter W/D letters.
This would be the code to scroll down when pressing W. 87 = W on Keyboard (code doesn't work correctly)
document.body.onkeyup = function(e) {
var code = e.keyCode;
if(code === 87) {
window.scrollTo(document.body.scrollLeft,
document.body.scrollBottom + 500);
}
};
How do I do this? And is there a way to scroll smooth so I don't click the keys, I can hold them?