私はHTML5を使用しており、マウスの移動中にマウスの右ボタンまたは左マウスボタンが押されているかどうかを知りたい。マウスの右ボタンには、右ボタンのevent.button = 2があります。左ボタンにはevent.button = 0があります。mousemoveの間は常にevent.button = 0です。私はいくつかのサンプルコードを提供しました。私は間違って何をしていますか?
demo on detecting mouse buttons
<meta charset="utf-8"/>
<script type="text/javascript">
function detectDown(event)
{
var string = "Mouse Down, event.button = " +event.button;
var canvas = document.getElementById("mycanvas");
var context = canvas.getContext("2d");
context.clearRect(0,0,300,20);
context.fillText(string,0,10);
}
function detectMove(event)
{
var string = "Mouse Move, event.button = " +event.button;
var canvas = document.getElementById("mycanvas");
var context = canvas.getContext("2d");
context.clearRect(0,30,300,20);
context.fillText(string,0,40);
}
function detectUp(event)
{
var string = "Mouse Up, event.button = " +event.button;
var canvas = document.getElementById("mycanvas");
var context = canvas.getContext("2d");
context.clearRect(0,60,300,20);
context.fillText(string,0,70);
}
</script>