Scratch for Java

Stage::isKeyPressed()

Returns true if the passed key is pressed.

Examples

import org.openpatch.scratch.*;

public class StageIsKeyPressed {
  public StageIsKeyPressed() {
    Stage myStage = new Stage(600, 240);

    while (myStage.getTimer().forMillis(3000)) {
      myStage.display("Space pressed? " + myStage.isKeyPressed(KeyCode.VK_SPACE));
    }
    myStage.exit();
  }

  public static void main(String[] args) {
    new StageIsKeyPressed();
  }
}

View on GitHub

Syntax

Java

.isKeyPressed(keyCode)

Scratch

Parameters

NameData TypeDescription
keyCodeintA key code. You can use the enum KeyCode. For example KeyCode.VK_SPACE.

Return

boolean