Action: Letkeymap(variable, keystring)

Related Actions: letmousex, letmousey, letkey
Related Events: keypress, keyrelease
See also: FKiSS, Events, Actions

letkeymap(variable, keystring)

First defined in: FKiSS4
The letkeymap action sets each bit in variable if the corresponding key in keystring is pressed.
If no key in keystring is pressed, variable is set to 0.

variable

variable must be a variable name.

keystring

keystring must be a string identifying one or more keys. The string is composed of one or more of the following sub-strings concatenated together (All other keys are ignored):
  • "up" (up arrow)
  • "down" (down arrow)
  • "left" (left arrow)
  • "right" (right arrow)
  • "space" (space bar)
  • "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
  • "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
keystring is case-insensitive.
keystring is processed in order from left to right. Each key specified corresponds to a single bit starting with bit 0. So if three keys are specified in keystring, for example, "ABC", a maximum of three bits might be set. For the example "ABC", bit 0 is set if "A" is pressed, bit 1 is set if "B" is pressed, and bit 2 is set if "C" is pressed. If you specify "CAB", then bit 0 is set if "C" is pressed, bit 1 is set if "A" is pressed, and bit 2 is set if "B" is pressed.
The value that is stored in variable is the sum of all the bits set, where each bit is a power of 2. The following table shows the powers of 2:
BitValueBitValue
0112
2438
416532
6647128
82569512
101024112048
124096138192
14163841532768
166553617131072
1826214419524288
201048576212097152
224194304238388608
24167772162533554432
266710886427134217728
2826843545629536870912
30107374182431-2147483648
It is recommended the cursor keys and space bar strings be put at the beginning of keystring in lowercase, and all single letters after that in uppercase followed by the digits. For example, "updownspaceABC0123".
A maximum of 32 keys can be tracked in one keystring.

Example:

; Watch for up arrow, down arrow, and "F".
; If only F is pressed, K = 4 (bit 2 is set; 2 raised to the power of 2 is 4).
; If up arrow and F are pressed, K = 5 (bit 2 and bit 0 are set: 2 to the power of 2 (4) plus 2 to the power of 0 (1) is 5).
;@ letkeymap(K, "updownF")