This shows you the differences between two versions of the page.
Last revision Both sides next revision | |||
api:keyboard:zh [2022/08/11 10:30] fight_xing created |
api:keyboard:zh [2023/10/14 17:46] hfsr [Keyboard API] translate |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | Keyboard API | + | Keyboard(键盘) API |
=========== | =========== | ||
+ | 此API提供了利用`keyboard.keys`表以按键名查找按键编码的功能。此表可双向查询。例如,`keyboard.keys.numpad0`的值为`0x52`,而`keyboard.keys[0x52]`的值为字符串`numpad0`。 | ||
- | **本篇文章的部分/全部内容还没有进行翻译。** | + | 请查阅[包含此API实现的Lua文件](https://github.com/MightyPirates/OpenComputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/loot/openos/lib/keyboard.lua)以获取可用键名的列表。 |
- | This API allows you to refer to key codes by name, using the `keyboard.keys` table. This is a two-directional table, for example, the value of `keyboard.keys.numpad0` is `0x52`, and the value of `keyboard.keys[0x52]` is the string `numpad0`. | + | 此外,此API还注册了事件侦听器以持续追踪每个按键的状态。这些内部状态值可以通过下列函数查阅: |
- | + | ||
- | Please see [the Lua file containing the API's implementation](https://github.com/MightyPirates/OpenComputers/blob/master-MC1.7.10/src/main/resources/assets/opencomputers/loot/openos/lib/keyboard.lua) for the list of available names. | + | |
- | + | ||
- | Additionally it registers event listeners to keep track of the state of individual keys. This internal state can be queried using the following functions: | + | |
- `keyboard.isAltDown(): boolean` | - `keyboard.isAltDown(): boolean` | ||
- | Checks if one of the Alt keys is currently being held by some user. | + | 检查Alt键是否正在被用户按住。 |
- `keyboard.isControl(char: number): boolean` | - `keyboard.isControl(char: number): boolean` | ||
- | Checks if the specified character (from a keyboard event for example) is a control character as defined by Java's `Character` class. Control characters are usually not printable. | + | 检查指定字符(例如来源于键盘事件的返回值)是否为Java的`Character`类定义的控制字符。控制字符通常不可显示。 |
- `keyboard.isControlDown(): boolean` | - `keyboard.isControlDown(): boolean` | ||
- | Checks if one of the Control keys is currently being held by some user. | + | 检查是否有控制按键正在被用户按住。 |
- `keyboard.isKeyDown(charOrCode: any): boolean` | - `keyboard.isKeyDown(charOrCode: any): boolean` | ||
- | Checks if a specific key is currently being by some user. If a number is specified it is assumed it's a key code. If a string is specified it is assumed it's a single character, such as the ones passed by keyboard events. | + | 检查指定按键是否正在被用户按住。如果指定数字,则假定其为按键编号。如果指定字符串,则假定其为单个字符,例如键盘事件返回的字符。 |
- `keyboard.isShiftDown(): boolean` | - `keyboard.isShiftDown(): boolean` | ||
- | Checks if one of the Shift keys is currently being held by some user. | + | 检查shift键是否正在被用户按住。 |
[keyboard]: https://github.com/MightyPirates/OpenComputers/assets/opencomputers/lua/rom/lib/keyboard.lua | [keyboard]: https://github.com/MightyPirates/OpenComputers/assets/opencomputers/lua/rom/lib/keyboard.lua |