keyhit functions
#2
One thing you might want to watch out for is super-high CPU usage loops.  For example:

Code: (Select All)
Function waitup
    Do
        x = _KeyHit
    Loop Until x < 0
    waitup = x
End Function

Written as the above, that code is going to use as much CPU power as it possibly can, and it's going to make the fans on your PC scream like an airplane engine...

Be user friendly and always remember to add a _LIMIT or a _DELAY to such loops so that your program will play nice with the OS and not try to hog resources which it doesn't need.  Example:

Code: (Select All)
Function waitup
    Do
        x = _KeyHit
        _DELAY .05 '1/20th of a second pause between loops
    Loop Until x < 0
    waitup = x
End Function

It'll keep CPU usage down, and you'll never notice a change in your program's usage at all.  Wink
Reply


Messages In This Thread
keyhit functions - by James D Jarvis - 05-11-2022, 03:01 PM
RE: keyhit functions - by SMcNeill - 05-11-2022, 03:20 PM
RE: keyhit functions - by James D Jarvis - 05-11-2022, 03:58 PM



Users browsing this thread: 1 Guest(s)