Button pressed? #Solved??!?! | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

Button pressed? #Solved??!?!

Hey everyone. Problem is... I'm trying to check if the arrow buttons was pressed (keydowned). My attempt works only after clicking somewhere inside of body... It's the higher thing i decided to check and here's the problem : If i just loaded the page - body isn't active (like we're clicking not inside of it,we're clicking somewhere in the window). So my keydown doesn't work until I'll click inside of body. That's exactly the problem.I need it to work without clicking inside of body. How I tried to do this : $('body').keydown(function(event) { if (event.keyCode == 37) { console.log('left key'); } if (event.keyCode == 38) { console.log('up key'); } if (event.keyCode == 39) { console.log('right key'); } if (event.keyCode == 40) { console.log('down key'); } }); So the question again just in case : How to check if I pressed the button right after loading the page without clicking anything ?

21st May 2017, 11:51 PM
Rose Sevenyears
Rose  Sevenyears - avatar
1 Respuesta
+ 1
Ehm...reloading browser fixed problem. Spent on tries to solve it like 3-4 hours... Feel it like a really bad joke....
21st May 2017, 11:56 PM
Rose Sevenyears
Rose  Sevenyears - avatar