Checks if the key specified was pressed.
Some interactive games use the keyboard for the user input to control the game. keyWentDown() generates a single true value when the key is pressed down, no matter how long a key is pressed. Use keyDown() to continually check if the key is pressed.
function draw() {
console.log(keyWentDown("left"));
}
Simple click counter using keyWentDown().
// Simple click counter using keyWentDown().
var count=0;
function draw() {
background("white");
if (keyWentDown("down")) count=count+1;
text(count, 200, 200);
}
keyWentDown(code)
| Name | Type | Required? | Description |
|---|---|---|---|
| code | String | The name of key you want to check. Keys without a letter or number have names like "up", "left", "shift", "tab", "space", etc. |
Boolean true or false.
Found a bug in the documentation? Let us know at documentation@code.org