or getKey(id).wait("first")

or getKey(id).wait(test)

Waits until a key is pressed.

If you call wait("first"), then if a valid key has been pressed since the creation of the key element, the next commands are evaluated and executed right away. If no valid key was pressed in the meantime, the next commands are only evaluated and executed after a valid key is pressed.

If you pass a test on an element as an argument, it only evaluates and executes the next commands when a valid key is pressed while the test is successful. If the test is not successful, it will be checked again upon the next key press.

[js highlight=”5″ try=”true”]newText(“instructions”, “Please press the spacebar”)
newKey(“space”, ” “)
newText(“thanks”, “Thank you!”)

Adds a text asking for a press of the spacebar key. The text Thank you! get printed below it only after the spacebar was pressed.