Detects the status of keys by keyboard scancode.
Syntax
Usage
result = MultiKey(scancode)
Parameters
Return Value
Returns -1 if the key for the specified
scan code is pressed, otherwise returns 0.
Description
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. This means you have to empty
Inkey when you finish using
MultiKey:
While Inkey <> "": Wend
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 statement. For a list of accepted scancodes, see
DOS keyboard scancodes; these are guaranteed to be valid for all FreeBASIC supported platforms.
MultiKey works both in console and graphics mode.
Example
#include "fbgfx.bi"
Dim work_page As Integer, x As Integer, y As Integer
' Request 640x480 with 2 pages
Screen 18, ,2
Color 2, 15
work_page = 0
x = 320
y = 240
Do
' Let's work on a page while we display the other one
ScreenSet work_page, work_page Xor 1
' Check arrow keys and update position accordingly
If MultiKey(FB.SC_LEFT) And x > 0 Then x = x - 1
If MultiKey(FB.SC_RIGHT) And x < 639 Then x = x + 1
If MultiKey(FB.SC_UP) And y > 0 Then y = y - 1
If MultiKey(FB.SC_DOWN) And y < 479 Then y = y + 1
Cls
Circle(x, y), 30, , , , ,F
' Page flip
work_page = work_page Xor 1
Loop While Not MultiKey(FB.SC_ESCAPE)
' Clear input buffer
While Inkey = "": Wend
' Restore both work and visible pages to page 0
ScreenSet
Print "Press CTRL and H to exit..."
Do
Sleep 25
If MultiKey(FB.SC_CONTROL) And MultiKey(FB.SC_H) Then Exit Do
Loop
Dialect Differences
- Not available in the -lang qb dialect unless referenced with the alias __Multikey.
Differences from QB
See also