Page 1 of 1
[Solved] Get key_sequence of hotkeys
Posted: Sun Aug 28, 2016 1:11 pm
by apriori
...how?
Code: Select all
data:extend({
{
type = "custom-input",
name = "modname-hotkey-main-window",
key_sequence = "Y",
consuming = "script-only"
}
})
How to get string value of key_sequence using API?
Re: Get key_sequence of hotkeys
Posted: Sun Aug 28, 2016 3:49 pm
by aubergine18
Just looked through relevant API docs and there doesn't seem to be any way whatsoever to get details about the key in-game.
You can get it during prototype initialisation by querying the custom-input objects in raw data table, so potentially you could choose different key if some other mod is already using your preferred key (would need to do it in data-final-fixes.lua as that's only place you could be sure all other mods have already defined their custom-inputs).
But there's no way to pass that information to something that control.lua could read...
...unless you go to the crazy extreme of defining new hidden item or tech that has it's .order set to value of key_sequence...
...but that's somewhat useless if user changes the keyboard shortcut via game options. :/
Observation: I found literally nothing that mentions custom-input in the official API guides (not even how to listen for the resulting event). Anyone reading the guide would be completely unaware that mods can define custom keyboard shortcuts.
Re: Get key_sequence of hotkeys
Posted: Sun Aug 28, 2016 6:11 pm
by apriori
There's almost no information about hotkeys and styles/fonts/sprites in API guide. I don't know where to look for it - only by analyzing other's mods.
I want to get key_sequence string to show it in a tooltip of LuaGuiElement as a remembering for player. Some (me too) have too many mods and these mods register it's own hotkeys. As for me, I can't remember all of them, so "tooltip-note" seems a good idea to me...
Re: Get key_sequence of hotkeys
Posted: Sun Aug 28, 2016 6:25 pm
by aubergine18
Yup, I want to do similar, but can't just hard-code it in case the player changes the key via game options screen. Also, I want to be able to automatically choose alternate key if some other mod is already using the preferred key.
I tried searching forums but anything with an underscore gets converted in to separate words which screws the search results up.
Re: Get key_sequence of hotkeys
Posted: Mon Aug 29, 2016 2:36 pm
by Rseding91
You can't read the key sequence through the game API because it can be different on each persons computer - it's not part of the game state.
It's the same reason you can't read translated text - each person can have a different language enabled.
Re: Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 8:48 am
by Choumiko
apriori wrote:Code: Select all
data:extend({
{
type = "custom-input",
name = "modname-hotkey-main-window",
key_sequence = "Y",
consuming = "script-only"
}
})
Setting a gui tooltip to
and in the locale file something like
Code: Select all
auto-trash-tooltip-pause = (__CONTROL__autotrash_pause__)
will show the hotkey for the custom input "autotrash_pause"
So probably best to ask the mod author(s) to add something like that.
Re: Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 10:53 am
by apriori
Choumiko wrote:Code: Select all
auto-trash-tooltip-pause = (__CONTROL__autotrash_pause__)
(__CONTROL__autotrash_pause__) - have you tried that? How can I find out which keywords should be used in this syntax construction? __CONTROL__what_should_be_here__
Re: Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 11:07 am
by aubergine18
Great idea about having special locale scope, although to differentiate from normal scopes maybe have different token style? @keyfor/custom-input.my_name
When we get mod settings feature, it could potentially be extended to handle per-user mod settings too.
Re: Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 2:37 pm
by apriori
Got it!
First of all you should "create" key sequence. You can do it in data.lua or in another lua (for example "prototypes/hotkey.lua") file and include it using require("prototypes.hotkey"):
[Optional] Then you create an event handler for your hotkey. And make a function to show LuaGuiElement with required tooltip/text:
Now you can include key sequence into locale:
It works!
PS: I dunno what will be in this tooltip if I'll change key sequence using game menu... Maybe, old sequence will be shown.
Re: [Solved] Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 3:39 pm
by aubergine18
Wow, the __CONTROL__ thing already existed?! Where do people get this information - I couldn't find this anywhere in API guide or wiki. @apriori do you have access to source code or something? Where did you find the infos?
Re: [Solved] Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 4:50 pm
by apriori
aubergine18 wrote:Wow, the __CONTROL__ thing already existed?! Where do people get this information - I couldn't find this anywhere in API guide or wiki. @apriori do you have access to source code or something? Where did you find the infos?
No. To my sorrow. Read above, Choumiko gave me some rows, and I tried to use it...
Re: [Solved] Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 5:29 pm
by DedlySpyder
Factorio IRC is normally the best place to get undocumented information. I believe that's where we got the pastebin for custom inputs when they first came out.
Re: [Solved] Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 5:49 pm
by apriori
DedlySpyder wrote:Factorio IRC is normally the best place to get undocumented information. I believe that's where we got the pastebin for custom inputs when they first came out.
How to join?
EDIT: found)))
EDIT: not found((( Is
that correct?
EDIT: alternative to desktop:
http://webchat.esper.net/?channels=#Factorio
Re: Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 6:10 pm
by apriori
apriori wrote:Got it!
First of all you should "create" key sequence. You can do it in data.lua or in another lua (for example "prototypes/hotkey.lua") file and include it using require("prototypes.hotkey"):
[Optional] Then you create an event handler for your hotkey. And make a function to show LuaGuiElement with required tooltip/text:
Now you can include key sequence into locale:
It works!
PS: I dunno what will be in this tooltip if I'll change key sequence using game menu... Maybe, old sequence will be shown.
Yes, old sequence is being shown.
Re: Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 7:01 pm
by DedlySpyder
apriori wrote:...
Yes, old sequence is being shown.
Meaning that the tooltip doesn't update? How much have you tested it? I assume a restart wouldn't change it, but does redrawing the GUI update it?
Re: Get key_sequence of hotkeys
Posted: Tue Aug 30, 2016 8:31 pm
by apriori
DedlySpyder wrote:
Meaning that the tooltip doesn't update? How much have you tested it? I assume a restart wouldn't change it, but does redrawing the GUI update it?
No, updating (destroy -> add) doesn't help. I think, because tooltip is {"localized-string"} is being loaded on game launch.
EDIT: But if you change hotkey in game controls and restart a game - tooltip become affected by changes.