Page 1 of 1

Allow linking custom-input to built-in hotkeys.

Posted: Wed Oct 25, 2017 9:14 am
by eradicator
What?
The ability to define a custom hotkey prototype so that it is always bound to the same key as a predefined built-in hotkey.
Whaaat?
For example i would like to get an event each time a player attempts to clear the cursor. This defaults to "Q" currently. So my current workaround is to define a custom-input that also binds to "Q". But i have no way to guarantee that my custom-input and the "clear cursor" built-in action are always bound to the same key if the player rebinds one of them.
The custom-input could show up in the mod-hotkeys menu either as an uneditable hotkey or simply not be shown at all (the latter is probably preferable from an "avoid player confusion" point-of-view).
"Simply" raising a moddable event for all built-in actions would work too, but might cost more performance?
Why?
In my mod i need to detect if and when a player attempts to clear the cursor even if the attempt fails due to full inventory. Also there are probably a number of similar cases where a mod function is logically bound to a certain input action.

Re: Allow linking custom-input to built-in hotkeys.

Posted: Wed Oct 25, 2017 9:27 am
by Lav
So essentially "lua callbacks for all keyboard-triggered events" if I understand you correctly. :-)

Re: Allow linking custom-input to built-in hotkeys.

Posted: Wed Oct 25, 2017 9:33 am
by JohnyDL
Or to be able to add Lua listen events to keybinds via less intrusive methods, maybe Get_Hotkey(drop_item) would return the hotkey for that and it only has to be run when hotkeys change as you can use it as a parameter to do the normal Lua listens

Re: Allow linking custom-input to built-in hotkeys.

Posted: Wed Oct 25, 2017 4:59 pm
by eradicator
Lav wrote:So essentially "lua callbacks for all keyboard-triggered events" if I understand you correctly. :-)
Yea. Like i said. Either raise events for everything or allow linking. The effect is the same. But i wouldn't know which way is cheaper on performance.

@Any moderator:
I just noticed i posted this in suggestions instead of "modding interface requests". Could anyone be so kind and move it?

Re: Allow linking custom-input to built-in hotkeys.

Posted: Wed Oct 25, 2017 7:37 pm
by Rseding91
I've added support to link a custom-input prototype directly to a game control for 0.16. When a custom-input is linked to a game control it won't show up in the control-settings GUI and will fire when the linked control is pressed.

Re: Allow linking custom-input to built-in hotkeys.

Posted: Wed Oct 25, 2017 9:35 pm
by eradicator
Rseding91 wrote:I've added support to link a custom-input prototype directly to a game control for 0.16. When a custom-input is linked to a game control it won't show up in the control-settings GUI and will fire when the linked control is pressed.
Rsed to the rescue! Thanks a lot again! :D :D

Can you supply example code? Or is it sufficient to do something like:

Code: Select all

(data.lua)
key_sequence = "__CONTROL__clear-cursor__"
Also can i still fetch the button name for localization from the linked custom hotkey, or do i need to fetch it from the link target?

Code: Select all

(control.lua)
game.players[x].print("",{"__CONTROL__my-hotkey__"})

Re: Allow linking custom-input to built-in hotkeys.

Posted: Wed Oct 25, 2017 10:27 pm
by Rseding91
You just leave key_sequence as an empty string or w/e - it doesn't matter - it won't be used except if you try to use it in locale. You define "linked_game_control" as the game key you want it to link to so "clear-cursor" in your example. You'd need to use the locale for "clear-cursor" since the game will ignore what ever you've defined for the custom input.