
|
| Mouse EventsRemember 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){
The variables mouseX and mouseY are given the horizontal and vertical coordinates of the cursor. Compensation for scrolling has been added.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 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. |