Zho:当 () 键被按下（积木）

The When Key Pressed 积木 is an 事件类积木 and a 半圆形积木. 程式 placed underneath this block will activate when the specified key is pressed.

The keys that can be sensed with this block include the entire English alphabet ( a b c etc.), the number keys ( 0 1 2 etc.), the arrow keys ( left up right down ), and the space key. After an update, this block now includes an any option, which allows one to press any key to operate the block.

In the 实验查看器, the enter key (or return key on Macs) could also be sensed.

The block will act similarly to typing text in a text box. There will be a delay between when the block first executes and the second time, but after that, there will be no delay until the key is released.

用法示例
This block is used to get input from the player, for a variety of uses.

Some common uses include:


 * Controlling an object

當 [空白 v] 鍵被按下 廣播訊息 [Fire! v] 重複 (5) 次 y 改變 (5) end


 * Typing on a word processor

當 [a v] 鍵被按下 造型換成 [a v] 蓋章 x 改變 (20)


 * Starting 动画类专案

當 [空白 v] 鍵被按下 廣播訊息 [Animation starts! v] 播放音效 [Intro v]


 * Moving around a map

當 [向上 v] 鍵被按下 y 改變 (15)

应用
This block can be partially replicated with the following code:

當 @greenflag 被點擊 重複無限次 如果 <[某 v] 鍵被按下？> 那麼 . . . end end

A more precise workaround:

when gf clicked 重複無限次 如果 <[某 v] 鍵被按下？> 那麼 廣播訊息 [ready v] end end

當收到訊息 [ready v] .. .

参见

 * 键被按下？