Mouse Events

Using the mouse events is probably harder than using Keyboard events as there are more of them. An important thing to note is the onMousewheel event handler is very new - only MSIE6 uses it. Users of other makes or older browsers may not be able to use the mouse wheel even if you have programmed it.
Remember the event handlers I specified on the previous page? These are the mouse related event handlers -
onMousemove="eHandle();" onMousedown="eHandle();" onMouseup="eHandle('mouseup');" onMousewheel="eHandle();"
Just for reference, here is the eHandle() function again-
function eHandle(et){
eType=et;
mouseX=event.clientX+document.body.scrollLeft;
mouseY=event.clientY+document.body.scrollTop;
mButs=event.button;
wheel+=event.wheelDelta/120;
var ky=event.keyCode;
keyB=ky
keys[ky]=1;
switch(eType){
case "mouseup":
mButs=0;
break;
case "keyup":
keyB=0;
keys[ky]=0;
break;
}
}
The variables mouseX and mouseY are given the horizontal and vertical coordinates of the cursor. Compensation for scrolling has been added.
The mButs variable stores a value between 0 and 7 depending on which buttons are held down.
When no buttons are pressed, the value is 0.
When the left button is down, 1 is added to the value.
When the right button is down, 2 is added to the value.
When the middle button is down, 4 is added to the value.
Finally, the wheel variable stores the last direction the mouse wheel was turned. If you rolled it up, 1 is returned. If you rolled it down, -1 is returned.
I have created a graphical display which tests this system out. Please not that only MSIE 6 or better supports the mouse wheel.
Wheel
X
Y