In the front-end design of the site, through the keyboard to control changes in page status, such as Up,down,pageup,pagedown and so on to the Web site scrolling. At present, the development of HTML5 brings a new game experience, so key operation is essential.
1. Monitor the mouse button.
Any keystroke operation must have a listener and a responder, so the mouse button is no exception. In the JS event operation, OnMouseDown is used to monitor the mouse button operation.
<!--Demo.html--> 2. Monitor keyboard keys
<script type= "Text/javascript" >function KeyDown () {var value= event.keycode var key = String.fromCharCode (Eve Nt.keycode) Alert "key:" + key + "value:" + value "}//Document.onkeydown = KeyDown; Document.body[0].onkeydown = KeyDown; document.getElementById (' canvas '). OnKeyDown = KeyDown; </script>
Mainstream application: In HTML5, use keystrokes to control the movement of sprites, backgrounds and other elements in the game.
try doing it;
JavaScript method for judging mouse buttons and keyboard keys