This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
api:event:zh [2023/11/29 13:05] hfsr [中断] |
api:event:zh [2023/11/29 13:11] (current) hfsr [通用事件处理函数] |
||
---|---|---|---|
Line 123: | Line 123: | ||
===== 通用事件处理函数 ===== | ===== 通用事件处理函数 ===== | ||
- | 此处提供了一个较好的通用事件处理函数。此样例中以`event.pull()`函数返回的事件ID作为回调函数列表的键,用元方法来处理未定义事件。请注意`event.pull`函数会让程序进入等待状态,直到出现可用事件。 | + | 此处提供了一个较好的通用事件处理函数。此样例的主要功能是以`event.pull()`函数返回的事件名称作为回调函数列表的键,用元方法来处理未定义事件。请注意`event.pull`函数会让程序进入等待状态,直到出现可用事件。 |
```lua | ```lua | ||
Line 165: | Line 165: | ||
event.listen("key_up", handleEvent) --注册handleEvent函数,使其在key_up事件发生时被调用,然后结束程序 | event.listen("key_up", handleEvent) --注册handleEvent函数,使其在key_up事件发生时被调用,然后结束程序 | ||
``` | ``` | ||
- | 也可以直接注册`myEventHandlers.key_up`,这样的话处理函数(`key_up`函数)会额外收到一个参数(事件名称)作为第一个参数。 | + | 也可以直接注册`myEventHandlers.key_up`,这样的话处理函数会额外收到一个参数(事件名称)作为第一个参数。 |
目录 | 目录 | ||
----------- | ----------- | ||
{{page>api:contents:zh&noheader&noeditbutton&nouser&nofooter}} | {{page>api:contents:zh&noheader&noeditbutton&nouser&nofooter}} |