Do something when mouse button has been released

Previous topic - Next topic

MrTAToad

Have you thought of acting on a graphic only when the mouse has been released ?  If not, it might be an idea to - it solves a lot of problems with multiple detection problems when the user just holds down a mouse button - unless, of course, that sort of thing is needed.

The following code deals with that sort of thing, returning TRUE in button1% and/or button2% only if the relevent button has been released after it has been pressed.

Code (glbasic) Select
// --------------------------------- //
// Project: Spots
// Start: Wednesday, November 19, 2008
// IDE Version: 6.075

TYPE tMouseState
mouseDown%[2]
ENDTYPE

GLOBAL mouseStates AS tMouseState

FUNCTION initMouseProcess:
mouseStates.mouseDown%[0]=FALSE
mouseStates.mouseDown%[1]=FALSE
ENDFUNCTION

FUNCTION mouseProcess:BYREF mx,BYREF my,BYREF button1%,BYREF button2%
LOCAL ma
LOCAL mb

MOUSESTATE mx,my,ma,mb
button1%=FALSE
button2%=FALSE

IF ma
mouseStates.mouseDown%[0]=TRUE
button1%=FALSE
ELSE
IF mouseStates.mouseDown%[0]=TRUE
button1%=TRUE
mouseStates.mouseDown%[0]=FALSE
ENDIF
ENDIF

IF mb
mouseStates.mouseDown%[1]=TRUE
button2%=FALSE
ELSE
IF mouseStates.mouseDown%[1]=TRUE
button2%=TRUE
mouseStates.mouseDown%[1]=FALSE
ENDIF
ENDIF
ENDFUNCTION

Hemlos

ye i use a special animation for mouse held buttons etc...makes it pretty :)
Bing ChatGpt is pretty smart :O

MrTAToad