Functions / keypress
keypress(fn)
keypress(function fn)
keypress( )

The keypress event is sent to an jCanvaScript object when the browser registers keyboard input. This is similar to the keydown event, except in the case of key repeats. If the user presses and holds a key, a keydown event is triggered once, but separate keypress events are triggered for each inserted character. In addition, modifier keys (such as Shift) trigger keydown events but not keypress events.

This event can be attached to any object, but the event is only sent to the object that has the focus and only if canvas element has the focus too. You can set focus to the object with .focus() function. In examples below you need to set focus on a canvases by click.

keypress(function fn)
return: object
Code
<script type="text/javascript">	
	function onload_1(idCanvas)	
	{	
		jc.start(idCanvas,true);
		jc.circle(100,120,50,'#ff0000',1)
			.focus()
			.keypress(function(key){
				alert(key.code);
			});
	}
</script>
<canvas id="canvas_1" tabIndex="0" width="250px" height="265px">
</canvas>
View
keypress( )
return: object
Code
<script type="text/javascript">	
	function start_2(idCanvas)
	{
		jc('#myCircle_2').keypress();
	}
	function stop_2(idCanvas)
	{
		jc('#myCircle_2')
			.color('#ff0000');
	}
	function onload_2(idCanvas)	
	{	
		jc.start(idCanvas,true);
		jc.circle(100,120,50,'#ff0000',1)
			.id('myCircle_2')
			.focus()
			.keypress(function(){
				var r = Math.floor(Math.random() * (254));
				var g = Math.floor(Math.random() * (254));
				var b = Math.floor(Math.random() * (254));
				this.color('rgb('+r+','+g+','+b+')');
			});
	}
</script>
<canvas id="canvas_2" tabIndex="1" width="250px" height="265px">
</canvas>
View