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. 知识库
  3. 二维积木
  4. 检测是否按下了鼠标键

检测是否按下了鼠标键

Scheduled Pinned Locked Moved 二维积木
1 Posts 1 Posters 766 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.
  • C Offline
    C Offline
    creaticodeteacher2-mail
    wrote on last edited by admin
    #1

    介绍

    可以用侦测类别中的这个布尔积木检测是否按下任意一个鼠标键:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/75f2359d-c108-48ff-aa71-47d94090ee34.png" width="600" style="border-radius: 5px; border: 1px solid #29622d;">

    如果鼠标键被按下,并且运行该积木的时候鼠标指针在舞台内,该积木就报告“true(真)”,否则就报告“false(假)”。

    Animation1.gif

     
     

    常见错误

    一个常见错误就是用单个积木“如果( )那么”来检测是否按下鼠标:

    Animation2.gif

    这行不通,因为当你点击绿旗按钮时,程序就迅速运行完这2个积木——“如果( )那么”和“鼠标键被按下?”。因此,当你点击绿旗之后再按下鼠标键,程序就没有反应,因为程序已经结束了。

     
     

    结合“重复执行”、“如果( )那么”

    大多数情况下,正确方式就是将积木“鼠标键被按下?”与积木“重复执行”、“如果( )那么”一起使用。这样的话,程序会重复不停地检测是否按下鼠标。

    例如,当按下鼠标时球转动,如下所示:

    Animation3.gif

     
    注意:在舞台上的任意位置按下鼠标即可使该积木报告“true(真)”。并不是非得在角色上点击。

    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