Page 1 of 1

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

Posted: Fri Jun 02, 2017 15:32
by Desour
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

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

Posted: Fri Jun 02, 2017 17:10
by GreenXenith
So... this allows for key events... but does it also allow for custom mouse clicks?

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

Posted: Fri Jun 02, 2017 18:18
by Desour
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.

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

Posted: Fri Jun 02, 2017 18:36
by GreenXenith
Like if the player uses the middle-mouse-button on a node or a side button or something can you make actions happen?

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

Posted: Fri Jun 02, 2017 20:21
by Nekrofage
Hi !!

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

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

Posted: Sat Jun 03, 2017 07:22
by Desour
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.

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

Posted: Sat Jun 03, 2017 10:11
by Desour
Update:
You can now set a filter if you want the events not for all keys but specific ones.

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

Posted: Sun Jun 04, 2017 09:03
by Nekrofage
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 !

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

Posted: Sun Jun 04, 2017 09:06
by Desour
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.