Source: JS Keyboard Inputs
I reduced the original size from 115b by 7 characters by using repeat.
This is a clever solution where it's finding u, d, l, r in the string using e.which which is the keyboard code and finding the index of it minus 37.
This is very cool to have in support small games in bookmarklets or other types of games with very little code.
Supporting arrow keys actually increases the size of the code significantly. We could reduce it by 21 characters if we don't support arrow keys.
<p id=o></p>
<script>
u=r=d=l=0;onkeydown=onkeyup=e=>this[`lurd${"*".repeat(24)}l**r************l*d***u**u`[e.which-37]]=e.type[5]
setInterval(() => o.innerHTML = JSON.stringify({u,r,d,l}), 30);
</script>u=r=d=l=0
onkeydown=onkeyup=e=>this['l**r************l*d***u**u'[e.which-65]]=e.type[5]Removing support for ZQSD only saves 3 characters.
u=r=d=l=0
onkeydown=onkeyup=e=>this['l**r**************d***u'[e.which-65]]=e.type[5]data:text/html,<meta charset=utf8><body style=margin:0;overflow:hidden onload="x=c.getContext`2d`;u=r=d=l=X=Y=0;onkeydown=onkeyup=e=>this['l**r************l*d***u**u'[e.which-65]]=e.type[5];setInterval`c.width=99;x.fillText('⚽',X+=l?-1:r?1:0,Y+=u?-1:d?1:0)`"><canvas id=c style=width:100vw;height:100vw>