> For the complete documentation index, see [llms.txt](https://wiki.redmodding.org/cyber-engine-tweaks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.redmodding.org/cyber-engine-tweaks/cet-functions/hotkeys/registerinput.md).

# RegisterInput

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.

## Definition

```lua
registerInput(slug, label, callback)
```

<pre class="language-lua"><code class="lang-lua">--
-- registerInput()
--
<strong>-- @param  string    slug      The internal slug (must be unique in your mod scope)
</strong>-- @param  string    label     The label displayed in CET Bindings
-- @param  function  callback  The callback function
--
registerInput('slug', 'label', function(keypress)
    
    if keypress then
        -- key is pressed
    else
        -- key is released
    end
    
end)
</code></pre>

## Alternative Usage

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.

```lua
registerInput('slug', 'label', function(keypress)
    
    -- bail early on key release
    if not keypress then
        return
    end
    
    -- key is pressed
    
end)
```

## Usage Note

{% hint style="warning" %}
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
  {% endhint %}

```lua
registerInput('slug', 'label', function(keypress)
    
    -- this will be called 2 times!
    
end)
```

## Usage Example

#### Activate slow motion effect as long as the input key is pressed:

{% code title="init.lua" %}

```lua
-- register input
registerInput('slow_motion', 'Slow Motion', function(keypress)
    
    -- get time system
    local timeSystem = Game.GetTimeSystem()
    
    -- bail early if time system doesn't exists
    if not timeSystem then
        return
    end
    
    -- key is pressed
    if keypress then
        timeSystem:SetTimeDilation('MySlowMo', 0.3)
        
    -- key is released
    else
        timeSystem:UnsetTimeDilation('MySlowMo')
    end


end)
```

{% endcode %}

## Advanced Example

#### Continuously give money as long as the input key is pressed:

{% hint style="info" %}
This example use the [onUpdate](/cyber-engine-tweaks/cet-functions/events/onupdate.md) event, which is triggered continuously. Make sure to [check the documentation](/cyber-engine-tweaks/cet-functions/events/onupdate.md) before any modification.
{% endhint %}

{% code title="init.lua" overflow="wrap" %}

```lua
-- set initial switch state
keep_giving = false

-- register input
registerInput('give_continuous_money', 'Give Continuous Money', function(keypress)

    -- input pressed
    if keypress then
        keep_giving = true -- switch on

    -- input released
    else
        keep_giving = false -- switch off
    end

end)

-- onUpdate
-- this event is triggered continuously
registerForEvent('onUpdate', function()
    
    -- check switch state
    if keep_giving then
        Game.AddToInventory('Items.money', 20)
    end

end)
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://wiki.redmodding.org/cyber-engine-tweaks/cet-functions/hotkeys/registerinput.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
