Capturing Keys

This effect goes with onkeydown statement. You can know what function it is. Here is the example code:

  function down() {	var code = window.event.keyCode	var real = String.fromCharCode(window.event.keyCode)	view.innerHTML = "Code: "+code+", realkey: "+real  }    document.onkeydown = down  

Here is the example.

You can make animation, when you hit the key. Just connect animation code and capturing code. Here is code example:

  function init() {	moving = mov.style	moving.xpos = parseInt(moving.left)	moving.move = 0	document.onkeydown = down	document.onkeyup = up  }   function down() {	var code = window.event.keyCode	if (code == 77 && !moving.move) {		moving.move = 1 		move();			}    }  function up() {	var code = window.event.keyCode	if (code == 77) {		moving.move = 0	}  }  function move() {	if (moving.move) {		moving.xpos += 5		moving.left = moving.xpos		setTimeout ("move()",30)	}  }  

Little harder than others. && !moving.move code is for stop the object. Try yourself and here is the example

Back to home.