keyWentUp()

Category:Game Lab

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.

Examples

function draw() {
  console.log(keyWentUp("A"));
}

Falling Star

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();
}
                        

Syntax

keyWentUp(code)

Parameters

NameTypeRequired?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.

Returns

Boolean true or false.

Tips

  • When testing your games that use keyboard or mouse input make sure you click in the display area before you run, otherwise the Workspace will record your keyboard and mouse actions.

Found a bug in the documentation? Let us know at documentation@code.org