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

User avatar
DS-minetest
Member
 
Posts: 1026
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

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

by DS-minetest » Fri Jun 02, 2017 15:32

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
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
GreenDimond
Member
 
Posts: 1197
Joined: Wed Oct 28, 2015 01:26
Location: A place
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

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

by GreenDimond » Fri Jun 02, 2017 17:10

So... this allows for key events... but does it also allow for custom mouse clicks?
My YuTube channel | I moderate the HOMETOWN Server. | Click here to see my (5) mods!
 

User avatar
DS-minetest
Member
 
Posts: 1026
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

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

by DS-minetest » Fri Jun 02, 2017 18:18

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.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
GreenDimond
Member
 
Posts: 1197
Joined: Wed Oct 28, 2015 01:26
Location: A place
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

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

by GreenDimond » Fri Jun 02, 2017 18:36

Like if the player uses the middle-mouse-button on a node or a side button or something can you make actions happen?
My YuTube channel | I moderate the HOMETOWN Server. | Click here to see my (5) mods!
 

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

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

by Nekrofage » Fri Jun 02, 2017 20:21

Hi !!

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

User avatar
DS-minetest
Member
 
Posts: 1026
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

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

by DS-minetest » Sat Jun 03, 2017 07:22

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.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
DS-minetest
Member
 
Posts: 1026
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

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

by DS-minetest » Sat Jun 03, 2017 10:11

Update:
You can now set a filter if you want the events not for all keys but specific ones.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

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

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

by Nekrofage » Sun Jun 04, 2017 09:03

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
DS-minetest
Member
 
Posts: 1026
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

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

by DS-minetest » Sun Jun 04, 2017 09:06

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.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 


Return to Client-side modding



Who is online

Users browsing this forum: No registered users and 0 guests