Detects the status of keys by keyboard scancode.

declare function Multikey ( byval scancode as long ) as long

result = Multikey(scancode)

The scan code of the key to check.

Return Value:
Returns -1 if the key for the specified scan code is pressed, otherwise returns 0.

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 manually when you finish using Multikey, using something like the following method:
While Inkey <> "": Wend '' loop until the Inkey buffer is empty

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 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.

#include ""
#if __FB_LANG__ = "fb"
Using FB '' Scan code constants are stored in the FB namespace in lang FB

Dim As Integer x, y

ScreenRes 640, 480

Color 2, 15

x = 320: y = 240
    ' 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
        ' Clear the screen and draw a circle at the position (x, y)
        Circle(x, y), 30, , , , ,F
    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..."

    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

Dialect Differences:
Differences from QB:
See also:
Back to User Input Functions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki phatcode