-1

Basically I want my character to jump if I press any button on the keyboard, is there a way to make it do this using "case..." functions? Thank you

Jordan

JordanK
  • 1
  • 1

1 Answers1

0

Add an event listener to the body or to the canvas element. Inspect the evt object in your console to see al its properties. it has for example ctrlKey and altKey pressed as a property which is probaly what you are looking for.

document.body.addEventListener('keydown',function(evt) {
e = evt || window.event;
var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
if (charCode > 0) {
  console.log("key pressed = "+ charcode);
  console.log(e);
}
});
Tschallacka
  • 27,901
  • 14
  • 88
  • 133