- "Key Pressed" redirects here. For the hat block that senses when a key is pressed, see When () Key Pressed (block).
[空白 v] 鍵被按下？
The keys available to be used in this block include the entire English alphabet ( 实验查看器, the key could also be chosen. After an update, this block now includes an option, which allows one to press any key to operate the block.etc.), the number keys ( etc.), the arrow keys ( ), and the key. In the
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!]
|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.
There are four somewhat popular suggestions related to this block:
- Add more keys
- Make a 椭圆形积木 that says what key is being pressed
- Allow drop-ins in the drop-down menu like in the costume drop-down menu (see Enabling Dropping for instructions on how to do this yourself by modifying the Squeak code)
- Make this a 舞台监控视窗
Some Scratch Modifications have at least one of these.