From Test-Scratch-Wiki

滑鼠鍵被按下?
滑鼠鍵被按下?
類別 偵測類積木
形狀 菱形積木

The Mouse Down? 積木 is a 偵測類積木 and a 菱形積木. The block checks if the 計算機的滑鼠's primary button is activated (being clicked).

用法示例

As this block checks if the mouse is being clicked, it is useful for simulating clicks anywhere, even on the 程式工作區 (not perfectly, however) and especially with 一角色一腳本類專案; if the 專案 requires clicking, this block can be used to serve as a replacement for the 當角色被點擊 block, as the 半圓形積木 cannot be used in the middle of a script.

Some common uses for the Mouse Down? block:

  • Sensing when an object should be lifted with the () 不成立 block (when the mouse is not held anymore)
重複無限次 
  如果 <滑鼠鍵被按下?> 那麼 
    等待直到 <<滑鼠鍵被按下?> 不成立>
    重複直到 <滑鼠鍵被按下?> 
      定位到 [滑鼠游標 v] 位置
    end
    等待直到 <<滑鼠鍵被按下?> 不成立>
  end
end
  • Sensing with draggable objects
  • Recording mouse clicks
當 @greenflag 被點擊
計時器重置
重複無限次 
  如果 <滑鼠鍵被按下?> 那麼 
    變數 [down v] 設為 (計時器)
    等待直到 <<滑鼠鍵被按下?> 不成立>
    變數 [up v] 設為 (計時器)
    變數 [elapsed v] 設為 ((up) - (down))
    新增項目 (down) \( [mouse-downs v] \)
    新增項目 (up) \( [mouse-ups v] \)
    新增項目 (elapsed) \( [down times v] \)
  end
end

Variants

In some Scratch modifications, there are similar blocks which allow the user to detect other mouse buttons; either the right-click or left-click button.

Some Scratchers wanted this feature to be implemented in Scratch itself.[1]

參見

參考

Cookies help us deliver our services. By using our services, you agree to our use of cookies.