Java Reference
In-Depth Information
↵
event.screenX + "," + event.screenY + ")");
}
Which Mouse Button Was Pressed?
The
event.which
property returns which mouse button or key was pressed. Try press-
ing the different mouse buttons (including the middle button) to see what is returned when
you change the
doSomething()
function to this:
function doSomething(event) {
console.log(event.which);
};
You should see a "1" in the console if you press the left mouse button, "2" if you press the
middle button, and "3" if you press the right button.
This is useful for finding out which mouse button was pressed, but there are more precise
methods of doing so that are discussed in the next section.
