Below is the code that checks when the left mouse button is pressed. A message is shown on the screen when is is down. It should be simple enough to see how other mouse buttons are done.
<!DOCTYPE = html> <html><body> <canvas id="myCanvas" width="150" style="border:1px solid #d3d3d3;"> Use different browser. </canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); var m="Left Mouse is not pressed"; gameloop = setInterval(doGameLoop,16); window.addEventListener("mousedown",mp,true); function doGameLoop(){ ctx.clearRect(0,0,c.width,c.height); ctx.fillText(m,10,10); } function mp(evt){ if(evt.which==1){ m="left mouse was pressed"; } } </script></body></html>
No comments:
Post a Comment