11-22-2022, 07:54 AM
Ever notice that some apps trigger an event when the left mouse is pressed, but a few trigger it only after the left mouse button once pressed is released? The following demonstrates how this can be accomplished...
Pete
Code: (Select All)
REM click_event = 1 to initiate on button press.
REM click_event = 2 to initiate on button release.
VIEW PRINT 1 TO 23
click_event = 1
LOCATE 25, 1: PRINT "Event triggered on left button press. Press 2 to change."
LOCATE 1, 1
DO
_LIMIT 30
b$ = INKEY$
IF LEN(b$) AND lb = 0 THEN
IF b$ = "1" THEN click_event = 1: y = CSRLIN: x = POS(0): LOCATE 25, 1: PRINT "Event triggered on left button press. Press 2 to change. ";: LOCATE y, x
IF b$ = "2" THEN click_event = 2: y = CSRLIN: x = POS(0): LOCATE 25, 1: PRINT "Event triggered on left button release. Press 1 to change.";: LOCATE y, x
END IF
WHILE _MOUSEINPUT: WEND
IF _MOUSEBUTTON(1) THEN
IF lb = 0 THEN lb = -1
ELSE
IF lb THEN
IF click_event = -2 THEN CALL event
lb = 0: click_event = ABS(click_event) ' Button release.
END IF
END IF
IF lb AND click_event = 1 THEN CALL event: click_event = -1 ' Event on button down.
IF lb AND click_event = 2 THEN click_event = -2 ' Event when button down is released.
LOOP
SUB event
SOUND 1000, .2
PRINT "Pete!"
END SUB
Pete