Repository navigation
Multikey
Home › User Input Functions (Graphics Library) › MultiKey
Returns -1 while the key with a given scancode is held down, or 0 if it is not.
Declare Function MultiKey ( ByVal scancode As Long ) As Longscancode
MultiKey is a function which will detect the status of any key, determined by scancode, at any time. It will return -1 if the key is pressed, otherwise it will return 0.
The keyboard input buffer is not disabled while you use MultiKey; that is, pressed keys will be stored and subsequently returned by your next call to Inkey or GetKey or Input. This means you have to empty the keyboard input buffer manually when you finish using MultiKey, using something like the following method:
While Inkey <> "": Wend '' loop until the keyboard input buffer is empty
For FB's built-in functionality of getting keyboard input, see Keyboard Input (Basics).
Keeping Inkey to work while you use MultiKey allows more flexibility and can be useful to detect Chr(255)+"k" combo returned on window close button click, if a windowed graphics mode has been set via the Screen (Graphics) statement. For a list of accepted scancodes, see DOS keyboard scancodes; these are guaranteed to be valid for all FreeBASIC supported platforms.
MultiKey should always work in graphics mode, as long as the screen is Unlocked. Support in the console depends on the platform the program is run on though, and cannot be guaranteed.
Returns -1 if the key for the specified scan code is pressed, otherwise returns 0.
result = MultiKey(scancode)
- Not available in the -lang qb dialect unless referenced with the alias
__Multikey.
- New to FreeBASIC
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB
#endif
Dim As Integer x, y
ScreenRes 640, 480
Color 2, 15
x = 320: y = 240
Do
' Check arrow keys and update the (x, y) position accordingly
If MultiKey(SC_LEFT ) And x > 0 Then x = x - 1
If MultiKey(SC_RIGHT) And x < 639 Then x = x + 1
If MultiKey(SC_UP ) And y > 0 Then y = y - 1
If MultiKey(SC_DOWN ) And y < 479 Then y = y + 1
' Lock the page while we work on it
ScreenLock
' Clear the screen and draw a circle at the position (x, y)
Cls
Circle(x, y), 30, , , , ,F
ScreenUnlock
Sleep 15, 1
' Run loop until user presses Escape
Loop Until MultiKey(SC_ESCAPE)
' Clear Inkey buffer
While Inkey <> "": Wend
Print "Press CTRL and H to exit..."
Do
Sleep 25
'' Stay in loop until user holds down CTRL and H at the same time
If MultiKey(SC_CONTROL) And MultiKey(SC_H) Then Exit Do
LoopCategory: User Input Functions (Graphics Library)
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.
- 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)
- 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