Allow linking custom-input to built-in hotkeys.

Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5202
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Allow linking custom-input to built-in hotkeys.

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
Lav
Filter Inserter
Filter Inserter
Posts: 384
Joined: Mon Mar 27, 2017 10:12 am
Contact:

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

Post by Lav »

So essentially "lua callbacks for all keyboard-triggered events" if I understand you correctly. :-)

JohnyDL
Filter Inserter
Filter Inserter
Posts: 515
Joined: Fri May 16, 2014 3:44 pm
Contact:

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

Post 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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5202
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Rseding91
Factorio Staff
Factorio Staff
Posts: 12150
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5202
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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__"})
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Rseding91
Factorio Staff
Factorio Staff
Posts: 12150
Joined: Wed Jun 11, 2014 5:23 am
Contact:

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

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Implemented mod requests”