Avorion

Avorion

Not enough ratings
Custom Hotkeys
   
Award
Favorite
Favorited
Unfavorite
Mods: Mod
File Size
Posted
Updated
209.428 KB
9 Mar, 2021 @ 1:42pm
28 Jul, 2021 @ 10:35am
10 Change Notes ( view )

Subscribe to download
Custom Hotkeys

Description
Allow mod authors to use remappable keybinds.
I made this mod to prevent hotkey conflicts before they start and promptly made my only mod that uses a hotkey use it.

Open your player menu and click the binding buttons to change them, you can cancel with escape.
Unbind things with right click.

Requires Bubbet's UI Elements for the namespacer, which is used to make this a clientside only mod attached to the musiccoordinator.lua

For Modders:
Registering the hotkey:
Register your hotkey in the player/client/customhotkeys.lua using the function RegisterHotkey(key_id, translatable_name, default_key, translatable_tooltip, category
Where key_id is the id of the key and is used in the callback later(when receiving messages about its press)
Translatable name is the label that shows up in the binding window as displayed in the screenshot
default key is a table that must have a "key" entry that is a number or entry from KeyboardKey(which is also a number)

ex: {key = KeyboardKey._V} with optional keys for shift, alt, control, and hold_time which is in seconds.
If you wanted your key unbound by default pass {key = -1}

translatable_tooltip: A string to be displayed when hovering over the text displayed(translatable_name)
category: A string to place similar binds in the same grouping

Receiving the messages about press:
In your scripts initialize register the player callback "CustomHotkeys_YOUR_KEY_ID_HERE" and pair it to a function.

ex: Player():registerCallback("CustomHotkeys_select_valuable", "callbackFunction")

Then the callback will be sent two parameters on press/release/hold. The type, which is defined in lib/customhotkeys_enums.lua and the hud state at the time, since it uses a onPostRenderHud callback to listen for key presses.
7 Comments
Der Liebe Frankie 23 Mar, 2024 @ 10:27am 
Will this mod let me navigate the game menus (such as click-click-"Escort Me") using keys instead of my mouse? Is there such a mod?
Nyrin 17 Sep, 2021 @ 8:56pm 
In the process of integrating this with my autopilot hotkey mod (https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=2597234464) , I found one small bug:

[code]
function CustomHotkeys:onGalaxyMapUpdate(timeStep)
return self:onPostRenderHud(5, timeStep) -- hud state 5 for map, which is not a part of PlayerStateType
end
[/code]

I think you read [code]PlayerStateType[/code] like any sane person would--which is to say zero-indexed. But lua... (╯°□°)╯︵ ┻━┻

[code]
enum PlayerStateType

Fly -- 1
BuildCraft -- 2
BuildTurret -- 3
Interact -- 4
Strategy -- 5
[/code]

Either that or they added in a state after you implemented it. Might want to use a bigger/more arbitrary dummy value just in case.

Effect of all that: hotkeys you want to work in strategy mode also end up unintentionally working on the galaxy map.

Loving the integration, though! You just need someone to make you a cool icon.
SirPhoenixBlood 14 Sep, 2021 @ 12:34am 
i had to make a whole new world for it to work but it was enable on the old world
Bubbet!  [author] 13 Sep, 2021 @ 12:29pm 
check your mods list in the escape menu when ingame to see if its even enabled
SirPhoenixBlood 13 Sep, 2021 @ 6:19am 
not working for me i dont get that tab at all
Shrooblord 10 Mar, 2021 @ 12:34am 
This is fricking sick. Good job bub!
Multox 9 Mar, 2021 @ 2:18pm 
Neat!