Repository navigation
Sleep
Home › Miscellaneous Keywords › Sleep
Waits until a specified time has elapsed, or a key is pressed.
Declare Sub Sleep ( ByVal amount As Long = -1 )
Declare Function Sleep ( ByVal amount As Long , ByVal keyflag As Long ) As Longamountkeyflag
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.
And using for the amount parameter values lower than these accuracy values does not allow Sleep to produce the corresponding wait values (always higher wait, and of the order of these values) except for the amount value '0'.
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 input buffer and any keys pressed during a call to Sleep are retained and can be later read by Inkey or GetKey or Input.
When Sleep has no parameters (waiting for a key pressed only), GetKey keyword can be used instead of Sleep.
For the general form of Sleep (with parameters), if the user want to clear the keyboard input buffer from any eventual keys pressed during the Sleep execution, he can use after the Sleep instruction line something like the following method:
While Inkey <> "": Wend '' loop until the keyboard input buffer is empty
Returns 1 if keyflag was not a valid value (i.e. something other than 0 or 1) to indicate failure, or 0 otherwise.
Sleep [ amount [, keyflag ]]
result = Sleep ( amount, keyflag )- In the -lang fb and -lang fblite dialects, the
amountvalue is in milliseconds. In the -lang qb dialect, theamountvalue is in seconds as in QB. If the second parameterkeyflagis given, or the keyword is written as__Sleepthe value is expected to be in milliseconds.
- None in the -lang qb dialect.
- In QB, the delay was given in whole seconds only and did not support the
keyflagparameter.
Print "press a key"
Sleep
GetKey '' clear the keyboard input buffer, and even in that code case, the 'Sleep' keyword can be outright omitted
Print "waiting half second"
Sleep 500Dim As String s
Print "wait 3 seconds or press a key"
Sleep 3000
Print "outputed by timeout or key pressed"
While Inkey <> "" '' loop until the keyboard input buffer is empty
Wend
Input "enter a string"; s
Print "string entered: " & "'" & s & "'"
SleepCategory: Miscellaneous Keywords
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing