[MOD] Callback API for key and mousebutton[1.0][controls]

Arcelmi
Member
Posts: 68
Joined: Mon Dec 28, 2015 16:24
GitHub: Arcelmi
IRC: Arcelmi
In-game: Arcelmi
Location: Germany

[MOD] Callback API for key and mousebutton[1.0][controls]

by Arcelmi » Post

Description:

This mod adds callbacks when a player press, hold or release a button.

Download Information:

Latest version: 1.0
Download
GitHub
License: GNU Lesser General Public License v2.1

API:

Spoiler
Syntax:

Code: Select all

controls.register_on_press(function(player, key))
Description:
Register a callback to be called when a player press a key or mousebutton.
  • player - ObjectRef
  • key - string (can be "jump", "right", "left", "LMB", "RMB", "sneak", "aux1", "down" or "up")
Example:

Code: Select all

controls.register_on_press(function(player, key)
    minetest.chat_send_all(player:get_player_name().." pressed the key "..key.."!")
end)
Spoiler
Syntax:

Code: Select all

controls.register_on_hold(function(player, key, time))
Description:
Register a callback to be called when a player is holding a key or mousebutton.
  • player - ObjectRef
  • key - string (can be "jump", "right", "left", "LMB", "RMB", "sneak", "aux1", "down" or "up")
  • time - number (time from press the button)
Example:

Code: Select all

controls.register_on_hold(function(player, key, time)
    minetest.chat_send_all(player:get_player_name().." is holding the key "..key.." for "..time.." seconds.")
end)
Spoiler
Syntax:

Code: Select all

controls.register_on_release(function(player, key, time))
Description:
Register a callback to be called when a player release a key or mousebutton.
  • player - ObjectRef
  • key - string (can be "jump", "right", "left", "LMB", "RMB", "sneak", "aux1", "down" or "up")
  • time - number (time from press the button)
Example:

Code: Select all

controls.register_on_release(function(player, key, time)
    minetest.chat_send_all(player:get_player_name().." released the key "..key.." after "..time.." seconds!")
end)
Last edited by Arcelmi on Tue Dec 12, 2017 16:44, edited 1 time in total.
I don't speak very good English... | My mods

I've got a signature!

User avatar
Desour
Member
Posts: 1473
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: [MOD] Callback API for key and mousebutton[controls][1.0

by Desour » Post

I have already done something like this: viewtopic.php?t=17780
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

Arcelmi
Member
Posts: 68
Joined: Mon Dec 28, 2015 16:24
GitHub: Arcelmi
IRC: Arcelmi
In-game: Arcelmi
Location: Germany

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Arcelmi » Post

Sorry I didn't see this...
Because I don't searched after something like this, because I wanted to update this with my bow mod.
I don't thought that somebody had make something like this.
I don't speak very good English... | My mods

I've got a signature!

Arcelmi
Member
Posts: 68
Joined: Mon Dec 28, 2015 16:24
GitHub: Arcelmi
IRC: Arcelmi
In-game: Arcelmi
Location: Germany

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Arcelmi » Post

Does your mod also handle key releases? I didn't see anything like this in your code.
I don't speak very good English... | My mods

I've got a signature!

User avatar
Desour
Member
Posts: 1473
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: [MOD] Callback API for key and mousebutton[1.0][controls

by Desour » Post

Arcelmi wrote:Does your mod also handle key releases? I didn't see anything like this in your code.
I think, I forgot that.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: [MOD] Callback API for key and mousebutton[controls][1.0

by azekill_DIABLO » Post

DS-minetest wrote:I have already done something like this: viewtopic.php?t=17780
it was CSM, this one is server side: a big improvement
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
Desour
Member
Posts: 1473
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: [MOD] Callback API for key and mousebutton[controls][1.0

by Desour » Post

azekill_DIABLO wrote:
DS-minetest wrote:I have already done something like this: viewtopic.php?t=17780
it was CSM, this one is server side: a big improvement
No, it was (and is) both.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by azekill_DIABLO » Post

okay. sorry. didn't senn it. need engine improvmements!
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
Wuzzy
Member
Posts: 4803
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Wuzzy » Post

Care to suggest to include this functionality into core Minetest, or at least builtin?

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by azekill_DIABLO » Post

Wuzzy wrote:include this functionality into core
Including a functionnality in the core... What it's possible?
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

User avatar
Desour
Member
Posts: 1473
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: [MOD] Callback API for key and mousebutton[1.0][controls

by Desour » Post

azekill_DIABLO wrote:
Wuzzy wrote:include this functionality into core
Including a functionnality in the core... What it's possible?
Minetest has some builtin lua stuff, someone could add this mod's functionality there as helper and make a pull request to the minetest github repository.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
azekill_DIABLO
Member
Posts: 7507
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO
Location: OMICRON
Contact:

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by azekill_DIABLO » Post

was ironic :D a builtin function would be simpler normally... but idk about the server connection... with builtin lua...
Gone, but not dead. Contact me on discord: azekill_DIABLO#6565
DMs are always open if you want to get in touch!

Arcelmi
Member
Posts: 68
Joined: Mon Dec 28, 2015 16:24
GitHub: Arcelmi
IRC: Arcelmi
In-game: Arcelmi
Location: Germany

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Arcelmi » Post

License changed to GNU Lesser General Public License v2.1
I don't speak very good English... | My mods

I've got a signature!

User avatar
TechNolaByte
Member
Posts: 465
Joined: Wed May 10, 2017 21:00
GitHub: TechNolaByte

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by TechNolaByte » Post

wow this will save me a lot of time with an ultimate armor suit which has tons of special ability's which each need key binds
The great quest of alchemy neither failed nor attained gold; programmers are those great alchemists who transmute caffeine into code.

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by texmex » Post

I need to check multiple keys at the same time. For instance, I want to check that Aux and Up is pressed at the same time while at the same time checking that no other keys are being pressed. How?

Can key be returned as a table instead? (key.up, key.sneak and so on)

User avatar
Lone_Wolf
Member
Posts: 2578
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Lone_Wolf » Post

Didn't realize there was a forums topic. Great mod!
May I suggest you add this mod to the Minetest ContentDB?
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by texmex » Post

keyevent mod is superior atm tbh.

User avatar
Lone_Wolf
Member
Posts: 2578
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Lone_Wolf » Post

texmex wrote:keyevent mod is superior atm tbh.
This mod was perfect for what I needed at the time. And it had been so long since I had seen the keyevent mod that I had forgotten it existed. Didn't help that it was in the CSM section (with no bold red letters saying it also doubled as a mod)
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
Joseph16
Member
Posts: 310
Joined: Tue Dec 06, 2016 05:35
In-game: smb3

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Joseph16 » Post

How do I use this? I installed it and tried to use the key release thing but I couldn't get it to work. Please explain how this mod works.
Testin' mines since 1989

u18398

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by u18398 » Post

Joseph13 wrote:How do I use this? I installed it and tried to use the key release thing but I couldn't get it to work. Please explain how this mod works.
This is an api. please ask google what an api is.
This mod is totally useless if you do not write mods for yourself
and you need to check for pressed keys in your mod.

User avatar
Joseph16
Member
Posts: 310
Joined: Tue Dec 06, 2016 05:35
In-game: smb3

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Joseph16 » Post

I know what an api is. I'm making my own mods. What I'm asking is how to I use it with a mod? I installed the mod and enabled it, but whenever I tried to use the mod's functions it does not work.
Testin' mines since 1989

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by texmex » Post

Use keyevent mod instead, it’s better. I can show you how to use that.

User avatar
Lone_Wolf
Member
Posts: 2578
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Lone_Wolf » Post

texmex wrote:Use keyevent mod instead, it’s better. I can show you how to use that.
I don't see any register_on_release() or register_on_hold() functions in that mod. I'm sticking with this one...
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by texmex » Post

You may get the same functionality by checking old_keys.

User avatar
Lone_Wolf
Member
Posts: 2578
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [MOD] Callback API for key and mousebutton[1.0][controls

by Lone_Wolf » Post

texmex wrote:You may get the same functionality by checking old_keys.
Is that just the state of the keys on the last check? If so that won't work for me without some extra modding I would rather not do
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

Post Reply

Who is online

Users browsing this forum: apercy and 33 guests