CodeBase - Mouse states - mouseup, mousedown and mousepress

Return to the CodeBase listing

Category: Input

Version: 1.0

0
0

Information

Uploaded: 5th Feb 2010 16:52

Modified: 1st Jan 1970 01:00

Author:  Fluffy Paul

Summary

A short subroutine which will let you detect separate mousedown, mousepress and mouse up events, as well as double clicks.

Full Description

This code features a subroutine which detects changes in the mouseclick() value, buffers them and sets up the following variables:<br /> <br /> MOUSE_mousedown<br /> MOUSE_mousepress<br /> MOUSE_mouseup<br /> <br /> These variables will contain the number of the mouse button which triggered them.<br /> <br /> Anatomy of a mouseclick:<br /> <br /> 1. mouseup, mousepress and mousedown are zero.<br /> 2. User clicks button 1<br /> 3. mousedown and mousepress equal 1 but mouseup is still zero.<br /> 4. In the next cycle mousedown now equals zero, mousepress equals 1 and mouseup is also zero.<br /> 5. User releases mouse.<br /> 6. mousedown and mousepress are both zero. Mouseup is equal to 1.<br /> 7. In the next cycle, assuming no other mouse buttons are being pressed, all three variables are zero again.<br /> <br /> Note that if mouse button two was pressed then all the 1's in the above example would actually be 2's.<br /> <br /> This routine also detects double clicks. It records the time the user triggers a mouseup and compares it to the previous time the user moused up. If the same button moused up within the time specified by MOUSE_doubleClickSpeed then a double click is triggered.<br /> <br /> A double click is represented by a negative mouseup value which is zero minus the number of the mouse button which double clicked.<br /> e.g. User double clicks button 2. MOUSE_mouseup equals -2 for one cycle.<br /> <br /> You may wish to alter the code so that double clicks are triggered by mousedowns or mousepresses.

Comments

No comments yet.