Subscribe to our YouTube channel.Tutorials and more athttps://www.youtube.com/c/QB64Team.
0 Members and 1 Guest are viewing this topic.
Oh wouldn't that be something! to match users latitude and longitude and time and show them their night sky. :)
Hi romichess,There is another conniption causing issue with the mouse you might want to be prepared for that TempodiBasic has alluded to.This involves executing some code when the mouse is clicked.The _MOUSEBUUTON(1) reading only tells you when the mouse button is being pressed and if you execute a block of code at that time, you are likely to execute it several times if the user is slow to release or the code is slow to read the mouse clear update, _Mousebutton(1) = 0.I have only recently seen a best solution by Steve to be clear of mouse button down condition before executing a "Mouse Click Event" block of code. I have only tested this in newly revised cSleep but looks good to me and you know Steve came up with it so it's got to be good (if it is bug free).A demo of the technique:Code: QB64: [Select]OPTION _EXPLICIT 'B+ actually this might be better than old version of cSleep because handles time also PRINT "Hello World, press key, click mouse or wait 5 secs for goodbye."cSleep 5PRINT "goodbye world" 'c for click + SLEEP, this does force you to commit to a max time to waitSUB cSleep (secsWait AS DOUBLE) 'wait for keypress or mouseclick, solves midnight problem nicely I think DIM wayt AS INTEGER, oldMouse AS INTEGER, k AS LONG, startTime AS DOUBLE startTime = TIMER wayt = 1 _KEYCLEAR WHILE wayt WHILE _MOUSEINPUT: WEND IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN wayt = 0 ' <<<<<<<<<< execute Mouse Click Event oldMouse = _MOUSEBUTTON(1) ' <<< this is Steve's cool way to get clear of mouse click k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: wayt = 0 IF TIMER - startTime < 0 THEN 'past midnight IF TIMER + 24 * 60 * 60 - startTime > secsWait THEN wayt = 0 ELSE IF TIMER - startTime >= secsWait THEN wayt = 0 END IF _LIMIT 30 WENDEND SUB 'here is steve's with midnight problem but really nice clear of mouse (and keypresses?)SUB Pause (time AS _FLOAT) DIM ExitTime AS _FLOAT, k AS LONG, oldMouse AS INTEGER _KEYCLEAR 'clear the keyboard buffer so we don't automatically exit the routine IF time <= 0 THEN ExitTime = 1.18E+1000 ELSE ExitTime = time + TIMER DO WHILE _MOUSEINPUT: WEND IF _MOUSEBUTTON(1) AND NOT oldMouse THEN EXIT SUB k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: EXIT SUB 'clear any stray key events so they don't mess with code outside the Pause. oldMouse = _MOUSEBUTTON(1) _LIMIT 10 LOOP UNTIL ExitTime < TIMEREND SUB The oldMouse variable helps us get clear of the mouse down condition before we execute our mouse click code.