<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[图形化块编程入门]]></title><description><![CDATA[<p dir="auto">不想写代码也能做宏。图形模式把脚本拆成一块一块，拖着拼起来就行，拼完照样编译、烧录。</p>
<p dir="auto">先讲清一件事：<strong>图形模式和文本模式是同一份脚本的两种看法。</strong> 不是两套东西，也不是「简单版」和「专业版」。你在图形里拖一个块，文本里就多一行；你在文本里改一行，切回图形看到的就是改过的样子。随时可以来回切。</p>
<h2>怎么切过去</h2>
<p dir="auto">宏编辑页工具栏<strong>最右端</strong>是编辑形态开关：</p>
<ul>
<li>左段 <code>&lt;/&gt;</code> → 文本模式</li>
<li>右段（叠块图标）→ 图形模式</li>
</ul>
<p dir="auto">点一下右段就切。软件会记住你上次用的形态，下次打开同一个宏自动恢复。</p>
<p dir="auto">工具栏左侧的<strong>编译</strong>和<strong>验证</strong>两个按钮对两种模式都管用，切到图形模式后不用回文本模式就能检查。</p>
<blockquote>
<p dir="auto">如果当前脚本里有图形模式暂时不支持的写法，切换会被<strong>拒绝</strong>——脚本内容不会改动，下方输出窗口会说明是哪一行无法转换成语句块。这种情况继续用文本模式编辑就行，不影响使用。</p>
</blockquote>
<h2>界面</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>区域</th>
<th>图形模式下的内容</th>
</tr>
</thead>
<tbody>
<tr>
<td>左栏</td>
<td>宏目录，和文本模式相同，选要编辑的宏</td>
</tr>
<tr>
<td>中栏</td>
<td>块画布。整段宏就是一条从上往下咬合的块链</td>
</tr>
<tr>
<td>右栏</td>
<td>块目录，按功能分组，可搜索</td>
</tr>
</tbody>
</table>
<p dir="auto">容器块（条件、循环、子程序）带一个「嘴部」，子语句落在嘴里——也就是缩进在它内部。</p>
<p dir="auto">右栏共 8 组：</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>分组</th>
<th>内容</th>
</tr>
</thead>
<tbody>
<tr>
<td>控制语句</td>
<td>条件分支、当型循环、计数循环、跳出循环、注释</td>
</tr>
<tr>
<td>条件与运算</td>
<td>且、或、非、比较、四则运算</td>
</tr>
<tr>
<td>数学</td>
<td><code>math.round</code> / <code>math.abs</code> / <code>math.random</code> / <code>math.tointeger</code> / <code>math.type</code></td>
</tr>
<tr>
<td>变量与数据</td>
<td>声明变量、变量赋值、数组、字符串变量、字符串数组</td>
</tr>
<tr>
<td>子程序</td>
<td>定义子程序、返回</td>
</tr>
<tr>
<td>键盘</td>
<td>KeyDown / KeyUp / KeyTap / ReleaseAllKeys / IsKeyDown / IsLockKeyOn</td>
</tr>
<tr>
<td>鼠标与坐标</td>
<td>MouseDown / MouseUp / MouseClick / IsMouseDown / MoveMouse / MoveMouseBy / ScrollMouse / TouchScreen / ScreenSize</td>
</tr>
<tr>
<td>延时与输出</td>
<td>Delay / Log / TypeText / GetUpTime</td>
</tr>
</tbody>
</table>
<p dir="auto">后续版本新增的命令如果还没归类，会出现在最后的「其他命令」组里，不会找不到。</p>
<h2>三种放入方式</h2>
<ol>
<li><strong>拖拽</strong>：从右栏拖到画布，落点出现插入线，松手插入到那个位置。拖到容器块的「嘴里」就是放进循环 / 条件内部。</li>
<li><strong>单击</strong>：插入到当前选中块的后面；画布上没有选中块时追加到末尾。</li>
<li><strong>返回值函数</strong>：<code>IsKeyDown</code>、<code>GetUpTime</code>、<code>math.*</code> 这些不是独立语句，放入后会自动生成一个 <code>result = 函数(...)</code> 的赋值块，光标停在括号里。把左边的变量名改成你要的即可。</li>
</ol>
<h2>改块上的内容</h2>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>元素</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr>
<td>白色字段</td>
<td>单击进入编辑，回车确认，Esc 取消</td>
</tr>
<tr>
<td>带下拉箭头的字段</td>
<td>单击弹出候选（存储类型、循环步长、运算符等）</td>
</tr>
<tr>
<td>块尾的 <code>+</code> / <code>x</code></td>
<td>增加一个参数槽 / 去掉最后一个。键盘、鼠标、Log 最多 16 个参数</td>
</tr>
<tr>
<td>数组下标小开关</td>
<td>打开后可以填序号，操作数组元素</td>
</tr>
</tbody>
</table>
<h2>值块不能单独成句</h2>
<p dir="auto">「条件与运算」和「数学」两组是<strong>值块</strong>：它们本身不产生动作，只产生一个值。所以不能直接放在语句链上，必须拖进条件槽或数值槽里。</p>
<p dir="auto">比如「条件且」拖到已经写好的条件上，会用「且」把两个条件连起来——这就是加第二个条件的做法。想给整个条件取反，用「条件非」。</p>
<p dir="auto">条件槽里的胶囊块可以<strong>直接单击中间的运算符</strong>切换：</p>
<ul>
<li>比较块：等于 / 不等于 / 小于 / 小于等于 / 大于 / 大于等于</li>
<li>四则块：加 / 减 / 乘 / 除以 / 整除 / 取余</li>
</ul>
<p dir="auto">想整段换成手写表达式：在条件上右键 →「编辑这段表达式…」。</p>
<h2>完整例子：连点 10 次、每次间隔 50ms</h2>
<ol>
<li>从右栏拖入「计数循环」，块面默认是 <code>i = 1 到 10</code>，保持不动；</li>
<li>从「鼠标与坐标」组把「MouseClick」拖进循环的嘴里；</li>
<li>单击块上的按钮参数，改成 <code>1</code>（左键）；</li>
<li>再从「延时与输出」组拖一个「Delay」进嘴里，填 <code>50</code>；</li>
<li>点工具栏<strong>编译</strong>检查语法，再点<strong>验证</strong>试跑。</li>
</ol>
<p dir="auto">切回文本模式，看到的就是：</p>
<pre><code class="language-lua">for i = 1, 10 do
    MouseClick(1)
    Delay(50)
end
</code></pre>
<h2>加个条件：按住才连点</h2>
<p dir="auto">想让它「按住某个键时才继续」，需要条件分支 + 值块：</p>
<ol>
<li>拖入「当型循环」，默认条件是 <code>true</code>；</li>
<li>从「键盘」组拖「IsKeyDown」到画布，它生成 <code>result = IsKeyDown(...)</code>——<strong>删掉这一句</strong>，改用另一种方式：直接把「条件与运算」里的比较块拖到循环的条件槽里；</li>
<li>比较块左边的槽填 <code>IsKeyDown("lshift")</code>（右键「编辑这段表达式」可以直接写），运算符选「等于」，右边填 <code>true</code>；</li>
<li>循环嘴里放 MouseClick 和 Delay。</li>
</ol>
<p dir="auto">对应的文本：</p>
<pre><code class="language-lua">while IsKeyDown("lshift") == true do
    MouseClick(1)
    Delay(50)
end
</code></pre>
<p dir="auto">这种写法不需要 ESC 兜底，条件不成立自己就退出了——比 <code>while true</code> 安全。</p>
<h2>什么时候该切回文本</h2>
<ul>
<li>脚本里出现图形模式不支持的写法（切换会被拒绝，会告诉你哪一行）；</li>
<li>需要精调表达式（右键「编辑这段表达式」也能写，但长的还是文本模式舒服）；</li>
<li>从别处拷来的脚本想先看一眼再改。</li>
</ul>
<p dir="auto">两边改的是同一份东西，不存在「图形模式下写的不算数」这种问题。</p>
]]></description><link>https://www.byteohm.com/topic/64/图形化块编程入门</link><generator>RSS for Node</generator><lastBuildDate>Thu, 19 Nov 2026 05:37:46 GMT</lastBuildDate><atom:link href="https://www.byteohm.com/topic/64.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Nov 2026 16:46:10 GMT</pubDate><ttl>60</ttl></channel></rss>