Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. Check if the mouse button is pressed down

Check if the mouse button is pressed down

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

    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”.

    p.gif

     
     

    A Common Mistake

    One common mistake is to check for the mouse press in a single “if” block like this:

    p.gif

    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.

     
     

    Combined with Forever + If

    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:

    p.gif

     
    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.

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode