Check if the mouse button is pressed down
CreatiCode last edited by
You can check if any mouse button is pressed down on the stage window using the following boolean block in the sensing category:
If the mouse button is pressed down and the pointer is inside the stage window at the moment this block is played, then it will report “true”; otherwise, it will report “false”.
One common mistake is to check for the mouse press in a single “if” block like this:
This won’t work because the program will run through the “if” and “mouse down?” blocks very quickly when you click the green flag button. Therefore, if you press down the mouse button after clicking the green flag, the program will not respond to you, because it has already ended.
Most of the time, the correct way is to use the “mouse down?” block together with a forever block and an “if” block. This way, the program will repeatedly check if the mouse is pressed down.
For example, we can turn the ball when the mouse is pressed down like this:
Note that you can press down the mouse anywhere on the stage to make this block report true. You do not need to click on the sprite.