controls/readme.md

36 lines
1.1 KiB
Markdown
Raw Normal View History

2023-12-04 09:00:10 +01:00
# Controls [controls]
2023-12-03 21:42:52 +01:00
2023-12-04 09:00:10 +01:00
[![luacheck](https://github.com/mt-mods/controls/workflows/luacheck/badge.svg)](https://github.com/mt-mods/controls/actions)
[![ContentDB](https://content.minetest.net/packages/mt-mods/controls/shields/downloads/)](https://content.minetest.net/packages/mt-mods/controls/)
Utility library for control press/hold/release events.
Rewritten and maintained version of [Arcelmi/minetest-controls](https://github.com/Arcelmi/minetest-controls).
## API
Callbacks are supported for all keys in `player:get_player_control()`.
2023-12-03 21:42:52 +01:00
```lua
controls.register_on_press(function(player, key)
2023-12-04 09:00:10 +01:00
-- Called when a key is pressed
-- player: player object
-- key: key pressed
2023-12-03 21:42:52 +01:00
end)
controls.register_on_hold(function(player, key, length)
2023-12-04 09:00:10 +01:00
-- Called every globalstep while a key is held
-- player: player object
-- key: key pressed
-- length: length of time key has been held in seconds
2023-12-03 21:42:52 +01:00
end)
controls.register_on_release(function(player, key, length)
2023-12-04 09:00:10 +01:00
-- Called when a key is released
-- player: player object
-- key: key pressed
-- length: length of time key was held in seconds
2023-12-03 21:42:52 +01:00
end)
2023-12-04 09:00:10 +01:00
```