From Test-Scratch-Wiki

Revision as of 02:48, 3 April 2018 by Dnowba (talk | contribs) (Created page with "{{:Eng:Key () Pressed? (block)/translate}} {{redirect|Key Pressed|the hat block that senses when a key is pressed|When () Key Pressed (block)}} {{Zho/积木 |名 = () 键被...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

"Key Pressed" redirects here. For the hat block that senses when a key is pressed, see When () Key Pressed (block).
() 键被按下?
[空白 v] 鍵被按下?
类别 侦测类积木
形狀 菱形积木

The Key () Pressed? 积木 is a 侦测类积木 and a 菱形积木. The block checks if the specified key is pressed. If the key is being pressed, the block returns "true"; if it is not, it returns "false".

The keys available to be used in this block include the entire English alphabet ( a b c etc.), the number keys ( 0 1 2 etc.), the arrow keys ( ), and the space key. In the 实验查看器, the ↵ Enter key could also be chosen. After an update, this block now includes an any option, which allows one to press any key to operate the block.

用法示例

As this block checks if a key is being pressed or not, it is useful for controlling objects, especially with 一角色一脚本类专案. If the 专案 requires key input, this block can be used to serve as a replacement for the 当 () 键被按下 block. The 半圆形积木 cannot be used in the middle of a script.

Some common uses for the Key () Pressed? block:

  • Controlling a character
重複無限次 
  如果 <[向下 v] 鍵被按下?> 那麼 
    y 改變 (-10)
  end
  如果 <[向上 v] 鍵被按下?> 那麼 
    y 改變 (10)
  end
  如果 <[向左 v] 鍵被按下?> 那麼 
    x 改變 (-10)
  end
  如果 <[向右 v] 鍵被按下?> 那麼 
    x 改變 (10)
  end
end
  • Word processors
  • Moving objects
  • Changing slides in slideshows or changing what characters say
說出 [Hello!]
等待直到 <[任何 v] 鍵被按下?>
等待直到 <<[任何 v] 鍵被按下?> 不成立>
說出 [Welcome to my game!]

Sensing Scrolling

Note Note: This only works offline.

The 当 () 键被按下 block, the counterpart to the Key () Pressed? block, senses the scroll wheel as well as the up/down keys. Combining these two blocks, it is possible to sense when somebody is using the scroll wheel. The following script is one way of doing this.

當 [向上 v] 鍵被按下
如果 <<[向上 v] 鍵被按下?> 不成立> 那麼 
  . . .
end

The action is done when the scroll wheel is scrolled up. If the key pressed blocks are changed to the down arrow, it will sense when it is scrolled down.

Suggestions

There are four somewhat popular suggestions related to this block:

Some Scratch Modifications have at least one of these.

参见


参考

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