HTML Canvas Key Event Key code
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Key Codes</title> </head>/*from w w w. j a va2 s .c om*/ <body> <aside>Open debugging console in web browser and press arrow key.</aside> <script> window.onload = function () { function onKeyboardEvent (event) { switch (event.keyCode) { case 38: console.log("up!"); break; case 40: console.log("down!"); break; case 37: console.log("left!"); break; case 39: console.log("right!"); break; default: console.log(event.keyCode); } } window.addEventListener('keydown', onKeyboardEvent, false); }; </script> </body> </html>