KEYDOWN

command

Return a held key’s code, or count the keys held down.

count = KEYDOWN(0) code = KEYDOWN(n)

count - number of keys currently held (0 when no key is down) n - index 1..KEYDOWN(0) of the held key to return

KEYDOWN(n) returns the Colour Maximite 2 code of the nth held key. Printable keys use their ASCII code; the arrows use Up=128, Down=129, Left=130, Right=131 and Escape is 27, the same values INKEY$ returns. The numeric keypad reports the same code as its top-row equivalent.

This is the CMM2 list contract: loop from 1 to KEYDOWN(0) and compare each KEYDOWN(n) against the code you want. To test one key, scan the list; there is no separate scan-code test. KEYDOWN() does not use PC/AT scan codes.

KEYDOWN() is a level: it reports the keys held right now. To react to a change instead of polling, install ON KEYDOWN; its handler runs once for each press or release (never for an operating-system repeat) and reads the new set with KEYDOWN().

See also INKEY$ and KEYBOARD CODES.

Example:

FOR i = 1 TO KEYDOWN(0)
  IF KEYDOWN(i) = 130 THEN x = x - 1
  IF KEYDOWN(i) = 131 THEN x = x + 1
NEXT i

Source: docs/help/keydown.txt inmmcore. On the computer, typeHELP KEYDOWN.