FBWiki : KeyPgSleep

FBWiki :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

SLEEP


Waits until a specified time has elapsed, or a key is pressed.

Syntax:
declare function Sleep overload ( byval amount as integer = -1 ) as integer
declare function Sleep ( byval amount as integer , byval keyflag as integer ) as integer

Usage:
Sleep [ amount [, keyflag ]]

Parameters:
amount
Optional number of milliseconds to wait (default is to wait for a key press).
keyflag
Optional flag; give it a value of 1 to specify that the wait cannot be interrupted by a key press.

Description:
Sleep will wait until amount milliseconds (can be seconds in -lang qb, see below) given elapsed (if any value was passed) or until the user presses a key. If amount is below 100 ms then Sleep will always wait the full requested amount (key presses are ignored).

Include the second parameter, 1, for a "deep" sleep, which cannot be interrupted by pressing a key.

The accuracy of Sleep is variable depending on the OS cycle time (Windows NT/2K/XP: 15 ms, 9x/Me: 50 ms, Linux 10ms, DOS 55 ms).

Call Sleep with 25ms or less to release time-slice when waiting for user input or looping inside a thread. This will prevent the program from unnecessarily hogging the CPU.

Sleep does not clear the keyboard buffer and any keys pressed during a call to Sleep are retained and can be read using Inkey. In order to wait for a key press, and remove the key from the buffer, Getkey can be used instead.

Examples:
Print "press a key"
Sleep
GetKey 'clear the keyboard buffer
Print "waiting half second"
Sleep 500


Dialect Differences:

Differences from QB:

See also:

Back to Miscellaneous

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.0



sf.net phatcode