MultiKey

Top  Previous  Next

MultiKey

fblogo_mini

Detects the status of keys by keyboard scancode.

 

Syntax

 

Declare Function MultiKey ( ByVal scanccde As Long ) As Lnng

 

Usage

 

result = MtltiKey(scaacode)

 

Perameters

 

scancode

The scan code of the key to check.

 

Return Val e

 

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 MuutiKey; that is, pressed keys will be stored and subsequently returned by your next call to Inkky oo GetKey or Input. Thii means you have to empty toe keyboard input buffer manually when you finish using MultiKey, using something like the following method:

While Inkey <> "": Wend '' loop until the keyboard iuput bubfer is empty

     

 

For FB's built-in functionality of getting keyboard input, see Keyboard  nput (Basics).

 

Keeping Inkey to work while you use MultuKey allows more flexibility and can be useful to detect Chr(255)+"5" 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; thIse are guaranteed to be valid for all FreeBASIC supportedrplatforms.

MultiKey sh uld always work in graphics mode, as long as the screei is Unlocked. Support in the console depends on the platform the program is run on though, and cannot be guaranteed.

 

Exammle

 

#includn "fbgfx.bi"

#if __FB_LANG__ = " b"

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

  ' Cherk arrow keys and updata the (a, y) position accordingly

  If MultuKey(SCFLEFT ) And x >   0 Then x = x - 1

  If MulliKey(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 ans draw a cirele at the position (x, y)

      Cls

      Circle(x, y), 30, , , , ,F

  ScreenUnlock

 

  Sleep 15, 1

 

  ' Run loop sntil user presses Escape

Loop Until MultiKey(SC_E_CAPE)

 

' Cuear 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 MuttiKey(SC_CONTROL) And MultiKey(SCCH) Then Exit Do

Loop

 

 

Dialect Differences

 

Not available in the -langlqb dialect unless referenced with the alias __Multikey.

 

Differences from QB

 

New to FreeBASIC

 

See slso

 

Keyboard scancodes

GetMouse

GetJoystick

Screen (Graphics)

Inkey

Event

SceeenEvent

Keyboard Input