Starts trapping keyboard events and sending them to
When a key is pressed down,
keydown is called.
When a key is released,
keyup is called.
You can determine the key that was pressed or released by calling KEYBOARDVALUE in your
keyup may either be a word that is the name of a procedure to call, or a list of commands.
Note the "Screen" must have focus (NOT the commander) to catch the key events.
You can force this by calling
SETFOCUS [FMSLogo] after you call KEYBOARDON.
All the "callbacks" for the keyboard are automatically run in NOYIELD mode.
For historical reasons, the set of keys that are captured when KEYBOARDON is given one input is different from the set of keys that are captured when it is given two inputs.
When only a
keydown input is given, the keys are trapped as characters, not as strict keydown events.
This means that lowercase a has a different value than uppercase A, even though the same key is pressed.
Because of this, a program that only looks for
ASCII "a doesn't work when Caps Lock is on.
This also means that when only one input is given to KEYBOARDON, it ignores keystrokes that don't have a textual character representation.
This includes ignoring the arrow keys, the function keys, most navigation keys, the Shift key, the Control key, and others.
In contrast, when KEYBOARDON has two inputs, it captures nearly all key events, including the arrow keys, the function keys, the navigation keys, the Shift key, and the Control key. Furthermore, each unique key press generates a separate callback. So uppercase A might generate the following keyboard events: a Shift keydown event, followed by an A keydown event, followed by an A keyup event, followed by a Shift keyup event.
Using KEYBOARDON on with one input to print characters that are typed:
KEYBOARDON [PRINT CHAR KEYBOARDVALUE] FULLSCREEN SETFOCUS [FMSLogo]
Press the 'A' key on the keyboarda
Press the 'B' key on the keyboardb
Using KEYBOARDON with two inputs to perform actions only while keys are held down:
TO ONKEYDOWN IF KEYBOARDVALUE = ASCII "T [ HIDETURTLE ] IF KEYBOARDVALUE = ASCII "S [ IF SCREENCOLOR <> 1 [SETSCREENCOLOR 1] ] END TO ONKEYUP IF KEYBOARDVALUE = ASCII "T [ SHOWTURTLE ] IF KEYBOARDVALUE = ASCII "S [ SETSCREENCOLOR 7 ] END (KEYBOARDON [ONKEYDOWN] [ONKEYUP]) FULLSCREEN
While you hold down the "T" key, the turtle hides. While you hold down the "S" key, the screen turns blue.