Checks if the key specified was released.
Some interactive games use the keyboard for the user input to control the game. keyWentup() generates a single true value when the key is released, no matter how long a key is pressed. Use keyDown()
to continually check if the key is pressed.
function draw() { console.log(keyWentUp("A")); }
Drop a star when the space bar is released.
// Drop a star when the space bar is released. var sprite = createSprite(200, 10); sprite.setAnimation("star"); sprite.scale=0.1; var drop=false; function draw() { if (keyWentUp("space")) drop=true; if (!drop) { if (keyDown("left")) sprite.x = sprite.x - 5; if (keyDown("right")) sprite.x = sprite.x + 5; background("white"); } else sprite.y = sprite.y + 10; drawSprites(); }
keyWentUp(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