Cyber Engine Tweaks allow mods to register hotkeys that can be assigned by the player in the CET Binding screen, and execute custom code once pressed. There are two kinds of hotkeys:
Hotkeys and Inputs, while having similar functionalities, are displayed in two separated groups.
Remember to register Hotkeys/Inputs at root level, outside of any event.
Hotkeys & Inputs are displayed in the CET Bindings screen sorted in the order they were registered in the code. If you want to sort hotkeys by label in ascending order for example, you'll have to change the registration code order accordingly.
Hotkeys & Inputs can be triggered by the user from anywhere, at anytime, as soon as CET loaded your mod (even earlier than onInit event).
Which means the user might press your hotkey in the Main Game Menu or in Settings Menu. You have to keep that in mind when working with hotkeys, and make sure your script is executed where it is supposed to.
Hotkeys & Inputs are triggered on top of the game's keybinds. Which means it's possible that player set a hotkey on "R".
In-game, when the player use "R" to trigger your script, it will also trigger the game's Reload function.
Hotkeys are buttons events triggered on key release. They must be registered using registerHotkey()
at root level, outside of any event, in the init.lua
file.
Inputs are buttons events that handle both key press and release states. They must be registered using registerInput()
at root level, outside of any event, in the init.lua
file.
The button state (press/release) is defined in the first argument passed to the callback.
You can register an Input and make it behave like a Hotkey. This method is more reactive as it triggers on key press, when a Hotkey is triggered on release.
It is important to check the keypress
argument inside the callback. Otherwise the code will be executed twice:
One time when the key is pressed
A second time when released
This example use the onUpdate event, which is triggered continuously. Make sure to check the documentation before any modification.