move 'input' library docs to a separate page

This commit is contained in:
MihailRis 2025-01-07 22:58:31 +03:00
parent 0d17396fe8
commit e5a3178969
6 changed files with 181 additions and 172 deletions

View File

@ -22,6 +22,7 @@ Subsections:
- [gfx.text3d](3d-text.md#gfxtext3d-library)
- [gui](scripting/builtins/libgui.md)
- [hud](scripting/builtins/libhud.md)
- [input](scripting/builtins/libinput.md)
- [inventory](scripting/builtins/libinventory.md)
- [item](scripting/builtins/libitem.md)
- [mat4](scripting/builtins/libmat4.md)

View File

@ -0,0 +1,89 @@
# *input* library
```lua
input.keycode(keyname: str) --> int
```
Returns key code or -1 if unknown
```lua
input.mousecode(mousename: str) --> int
```
Returns mouse button code or -1 if unknown
```lua
input.add_callback(bindname: str, callback: function)
```
Add binding activation callback. Example:
```lua
input.add_callback("hud.inventory", function ()
print("Inventory open key pressed")
end)
```
Callback may be added to a key.
```lua
input.add_callback("key:space", function ()
print("Space pressed")
end)
```
You can also bind the function lifetime to the UI container instead of the HUD.
In that case, `input.add_callback` may be used until the `on_hud_open` is called.
```lua
input.add_callback("key:escape", function ()
print("NO")
return true -- prevents previously assigned functions from being called
end, document.root)
```
```lua
input.get_mouse_pos() --> {int, int}
```
Returns cursor screen position.
```lua
input.get_bindings() --> strings array
```
Returns all binding names.
```lua
input.get_binding_text(bindname: str) --> str
```
Returns text representation of button by binding name.
```lua
input.is_active(bindname: str) --> bool
```
Checks if the binding is active.
```lua
input.set_enabled(bindname: str, flag: bool)
```
Enables/disables binding until leaving the world.
```lua
input.is_pressed(code: str) --> bool
```
Checks input activity using a code consisting of:
- input type: *key* or *mouse*
- input code: [key name](#key names) or mouse button name (left, middle, right)
Example:
```lua
if input.is_pressed("key:enter") then
...
end
```

View File

@ -25,89 +25,4 @@ packid.binding.name="inputtype:codename"
## *input* library
```python
input.keycode(keyname: str) -> int
```
Returns key code or -1 if unknown
```python
input.mousecode(mousename: str) -> int
```
Returns mouse button code or -1 if unknown
```python
input.add_callback(bindname: str, callback: function)
```
Add binding activation callback. Example:
```lua
input.add_callback("hud.inventory", function ()
print("Inventory open key pressed")
end)
```
Callback may be added to a key.
```lua
input.add_callback("key:space", function ()
print("Space pressed")
end)
```
You can also bind the function lifetime to the UI container instead of the HUD.
In that case, `input.add_callback` may be used until the `on_hud_open` is called.
```lua
input.add_callback("key:escape", function ()
print("NO")
return true -- prevents previously assigned functions from being called
end, document.root)
```
```python
input.get_mouse_pos() -> {int, int}
```
Returns cursor screen position.
```python
input.get_bindings() -> strings array
```
Returns all binding names.
```python
input.get_binding_text(bindname: str) -> str
```
Returns text representation of button by binding name.
```python
input.is_active(bindname: str) -> bool
```
Checks if the binding is active.
```python
input.set_enabled(bindname: str, flag: bool)
```
Enables/disables binding until leaving the world.
```python
input.is_pressed(code: str) -> bool
```
Checks input activity using a code consisting of:
- input type: *key* or *mouse*
- input code: [key name](#key names) or mouse button name (left, middle, right)
Example:
```lua
if input.is_pressed("key:enter") then
...
end
```
See [*input* library](builtins/libinput.md)

View File

@ -22,6 +22,7 @@
- [gfx.text3d](3d-text.md#библиотека-gfxtext3d)
- [gui](scripting/builtins/libgui.md)
- [hud](scripting/builtins/libhud.md)
- [input](scripting/builtins/libinput.md)
- [inventory](scripting/builtins/libinventory.md)
- [item](scripting/builtins/libitem.md)
- [mat4](scripting/builtins/libmat4.md)

View File

@ -0,0 +1,88 @@
# Библиотека *input*
```lua
input.keycode(keyname: str) --> int
```
Возвращает код клавиши по имени, либо -1
```lua
input.mousecode(mousename: str) --> int
```
Возвращает код кнопки мыши по имени, либо -1
```lua
input.add_callback(bindname: str, callback: function)
```
Назначает функцию, которая будет вызываться при активации привязки. Пример:
```lua
input.add_callback("hud.inventory", function ()
print("Inventory open key pressed")
end)
```
Можно назначить функцию на нажатие клавиши.
```lua
input.add_callback("key:space", function ()
print("Space pressed")
end)
```
Также можно привязать время жизни функции к UI контейнеру, вместо HUD.
В таком случае, `input.add_callback` можно использовать до вызова `on_hud_open`.
```lua
input.add_callback("key:escape", function ()
print("NO")
return true -- предотвращает вызов назначенных ранее функций
end, document.root)
```
```lua
input.get_mouse_pos() --> {int, int}
```
Возвращает позицию курсора на экране.
```lua
input.get_bindings() --> массив строк
```
Возвращает названия всех доступных привязок.
```lua
input.get_binding_text(bindname: str) --> str
```
Возвращает текстовое представление кнопки по имени привязки.
```lua
input.is_active(bindname: str) --> bool
```
Проверяет активность привязки.
```lua
input.set_enabled(bindname: str, flag: bool)
```
Включает/выключает привязку до выхода из мира.
```lua
input.is_pressed(code: str) --> bool
```
Проверяет активность ввода по коду, состоящему из:
- типа ввода: key (клавиша) или mouse (кнопка мыши)
- код ввода: [имя клавиши](#имена-клавиш) или имя кнопки мыши (left, middle, right)
Пример:
```lua
if input.is_pressed("key:enter") then
...
end
```

View File

@ -23,89 +23,4 @@ packid.binding.name="inputtype:codename"
## Библиотека input
```python
input.keycode(keyname: str) -> int
```
Возвращает код клавиши по имени, либо -1
```python
input.mousecode(mousename: str) -> int
```
Возвращает код кнопки мыши по имени, либо -1
```python
input.add_callback(bindname: str, callback: function)
```
Назначает функцию, которая будет вызываться при активации привязки. Пример:
```lua
input.add_callback("hud.inventory", function ()
print("Inventory open key pressed")
end)
```
Можно назначить функцию на нажатие клавиши.
```lua
input.add_callback("key:space", function ()
print("Space pressed")
end)
```
Также можно привязать время жизни функции к UI контейнеру, вместо HUD.
В таком случае, `input.add_callback` можно использовать до вызова `on_hud_open`.
```lua
input.add_callback("key:escape", function ()
print("NO")
return true -- предотвращает вызов назначенных ранее функций
end, document.root)
```
```python
input.get_mouse_pos() -> {int, int}
```
Возвращает позицию курсора на экране.
```python
input.get_bindings() -> массив строк
```
Возвращает названия всех доступных привязок.
```python
input.get_binding_text(bindname: str) -> str
```
Возвращает текстовое представление кнопки по имени привязки.
```python
input.is_active(bindname: str) -> bool
```
Проверяет активность привязки.
```python
input.set_enabled(bindname: str, flag: bool)
```
Включает/выключает привязку до выхода из мира.
```python
input.is_pressed(code: str) -> bool
```
Проверяет активность ввода по коду, состоящему из:
- типа ввода: key (клавиша) или mouse (кнопка мыши)
- код ввода: [имя клавиши](#имена-клавиш) или имя кнопки мыши (left, middle, right)
Пример:
```lua
if input.is_pressed("key:enter") then
...
end
```
См. [библиотека *input*](builtins/libinput.md)