[(Client)Mod] Event on Key Press [keyevent]

Post Reply
User avatar
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

[(Client)Mod] Event on Key Press [keyevent]

by Desour » Post

Keyevent

Adds an event for when player presses a key.
Look into README.md for more information.

This mod can be used as mod and as clientmod.

License: CC0

Download
Github
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
GreenXenith
Member
Posts: 1356
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
Location: UTC-8:00
Contact:

Re: [(Client)Mod] Event on Key Press [keyevent]

by GreenXenith » Post

So... this allows for key events... but does it also allow for custom mouse clicks?
YouTube | Mods | Patreon | Minetest Discord @greenxenith

You should not be able to read this message.

User avatar
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: [(Client)Mod] Event on Key Press [keyevent]

by Desour » Post

GreenDimond wrote:So... this allows for key events... but does it also allow for custom mouse clicks?
It uses player:get_player_control_bits(). I'm not sure what you mean with custom mouse clicks.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
GreenXenith
Member
Posts: 1356
Joined: Wed Oct 28, 2015 01:26
GitHub: GreenXenith
Location: UTC-8:00
Contact:

Re: [(Client)Mod] Event on Key Press [keyevent]

by GreenXenith » Post

Like if the player uses the middle-mouse-button on a node or a side button or something can you make actions happen?
YouTube | Mods | Patreon | Minetest Discord @greenxenith

You should not be able to read this message.

Nekrofage
Member
Posts: 52
Joined: Mon Oct 17, 2016 21:12
GitHub: Nekrofage

Re: [(Client)Mod] Event on Key Press [keyevent]

by Nekrofage » Post

Hi !!

Do you have a small example how to use the keyevent.register_on_keypress_bits() function?
Thank you !! :D

User avatar
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: [(Client)Mod] Event on Key Press [keyevent]

by Desour » Post

GreenDimond wrote:Like if the player uses the middle-mouse-button on a node or a side button or something can you make actions happen?
It don't think this is possible with the api.

@Nekrofage: Sure.
Client-side:

Code: Select all

keyevent.register_on_keypress_bits(function(keys, old_keys, dtime)
minetest.display_chat_message(keys)
end)
Server-side:

Code: Select all

keyevent.register_on_keypress(function(keys, old_keys, dtime, player_name)
local t = {s = {}, b = {}}
for k, v in pairs(keys) do
if v ~= old_keys[k] then
local bs = (v and "b") or "s"
t[bs][#t[bs]+1] = k
end
end
local msg = player_name.." stopped pressing "
for i = 1, #t.s do
msg = msg..t.s[i]..", "
end
msg = msg:sub(1, -3).."and began pressing "
for i = 1, #t.b do
msg = msg..t.b[i]..", "
end
msg = msg:sub(1, -3).."."
minetest.chat_send_all(msg)
end)
It's untested.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: [(Client)Mod] Event on Key Press [keyevent]

by Desour » Post

Update:
You can now set a filter if you want the events not for all keys but specific ones.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

Nekrofage
Member
Posts: 52
Joined: Mon Oct 17, 2016 21:12
GitHub: Nekrofage

Re: [(Client)Mod] Event on Key Press [keyevent]

by Nekrofage » Post

Hi DS !

In the example code, for the 'keyevent.register_on_keypress_bits()' method, I have this error:
attempt to index global 'keyevent' (a nil value)
Do you have informations about this error?
Thank you !

User avatar
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: [(Client)Mod] Event on Key Press [keyevent]

by Desour » Post

Nekrofage wrote:Hi DS !

In the example code, for the 'keyevent.register_on_keypress_bits()' method, I have this error:
attempt to index global 'keyevent' (a nil value)
Do you have informations about this error?
Thank you !
Since you took the csm example, it's most likely that you forgot to activate the mod in clientmods/mods.conf.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests