Sprite::isKeyPressed()
Returns true if the passed key is pressed.
Examples

import org.openpatch.scratch.*;
public class SpriteIsKeyPressed {
public SpriteIsKeyPressed() {
Stage myStage = new Stage(600, 240);
Sprite mySprite = new Sprite("zeta", "assets/zeta_green_badge.png");
mySprite.changeX(-80);
mySprite.changeY(30);
myStage.add(mySprite);
while (myStage.getTimer().forMillis(3000)) {
mySprite.say("Space pressed? " + mySprite.isKeyPressed(KeyCode.VK_SPACE));
}
myStage.exit();
}
public static void main(String[] args) {
new SpriteIsKeyPressed();
}
}
Syntax
Java
.isKeyPressed(keyCode)
Scratch
key [space v] pressed?
Parameters
Name | Data Type | Description |
---|---|---|
keyCode | int | A key code. You can use the enum KeyCode. For example KeyCode.VK_SPACE. |
Return
boolean