IF you guys want to see why mouseinput lags up, here's a quick example for you explaining the situation:
count = count + 1
runtimer = -1
count = count + 1
Print count;
"mouse events in one second."
Run the program, drag the mouse around... See how many mouse x/y change events you generate in a single second. On my laptop, with the trackpad, I get close to 100 updates per second.
Now, change the $LET to false. You are now tracking ALL mouse reports in a single second and not just the change events that I marked before. With my laptop, with the trackpad, I'm getting close to 600 updates per second.
Now, toss that in a program that runs with a _LIMIT of 60 times per second, and it's going to take you one and a half seconds to just read and react to the change states, and about 10 seconds if you try to process each and every mouse update in that second!
There's no two ways about it, in a situation like that, you end up generating lag with each user input! It takes 1.5 seconds to process 1 second of mouse activity (at _LIMIT 60... _LIMIT 30, would of course, take twice as long, whereas a _LIMIT 120 may not have noticeable lag at all, as long as the program and PC allows you to run at such a high number of loops per second.)
The way we fix this issue is to simply clear the buffer and only deal with the state when we need it.
DO
WHILE _MOUSEINPUT:WEND
x = _mousex: y = _mousey
LOCATE 1,1: PRINT x, y
_LIMIT 30
LOOP UNTIL _MOUSEBUTTON(1)
With the above, we clear the mouse buffer with the while-wend statements, and only deal with the mouse state 30 times a second, when our loop processes. Why would we give a crap where our mouse was located at in the microseconds before we read it??
At 0.000 microseconds the mouse was at 100,100
At 0.010 microseconds the mouse was at 101,100
At 0.020 microseconds the mouse was at 101,101
At 0.030 microseconds the mouse was at 102,101
At 0.040 microseconds the mouse was at 102,102 >-- We read it here.
At 0.050 microseconds the mouse was at 103,102
At 0.060 microseconds the mouse was at 103,103 >-- We read it here.
Every 0.033 seconds we make a loop (30 times a second). Why do we care where the mouse was at 0.01 seconds? At 0.02 seconds? We can toss those X/Y coordinates out as we can't process them without generating a backlog of activity. Our program is running a loop ever 0.033 seconds, so we only need to know the X/Y coordinates during the refresh of each run cycle.
While-wend the buffer away to only deal with updates when your main loop cycles back around.
The ONLY thing that you should ever have inside those while-wend loops is a mousewheel checker, if you're using it in your program. Everything else is just doing it wrong.
WHILE _MOUSEINPUT
MouseScroll = MouseScroll + _MouseWheel
WEND