> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebind.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# rb.input

> Read which keys and buttons are held, the cursor, controller axes, and input devices.

`rb.input` reads input as Rebind sees it: which keys, mouse buttons and
controller buttons are held and for how long, the cursor position, the
modifiers, controller axes, and the devices Rebind has identified. A script
reaches for it inside a handler or bind to check what else is held at that
moment.

This script runs on F and lets it through. With Ctrl held it logs the cursor
position, and with W held it logs how long W has been down:

```luau theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
-- rebind: min_sdk=3.9.0 name=example version=1.0.0
rb.bind("F", function()
  local pos = rb.input.mouse_pos()
  if rb.input.modifiers().ctrl then
    rb.log.info("Ctrl+F at", pos.x, pos.y)
  elseif rb.input.is_down("W") then
    rb.log.info("F while W held for", rb.input.duration("W"), "ms")
  end
end, { swallow = false })
```

| Signature | Returns |
| - | - |
| `rb.input.is_down(code: string) -> boolean` | whether the key, mouse button, or controller button is held |
| `rb.input.duration(code: string) -> number` | milliseconds the key, mouse button, or controller button has been held, `0` when it is not |
| `rb.input.axis(name: string) -> number` | a controller axis, `0` at rest; an unknown name raises `Input.GetAxis: unknown axis '<name>'`; `min_sdk` 3.11.0 |
| `rb.input.devices() -> { InputDevice }` | the devices Rebind has identified, described under [Devices](https://docs.rebind.gg/reference/sdk/events.md#devices); empty in software mode; `min_sdk` 3.12.0 |
| `rb.input.keys() -> { string }` | every held key, mouse button and controller button |
| `rb.input.mouse_pos() -> MousePos` | `{ x, y }`, the cursor position |
| `rb.input.modifiers() -> ModifierState` | `{ ctrl, shift, alt, win }` booleans, either side |

`code` uses the names handlers receive, with case ignored. An unknown name
returns `false` or `0`, except that `rb.input.axis` raises on one. A controller button name such as `"PadA"`
needs `min_sdk=3.11.0`; see [Controllers](https://docs.rebind.gg/reference/sdk/keys.md#controllers). For the
exclusive-capture rule of `down` and `up` handlers, see
[Input events](https://docs.rebind.gg/reference/sdk/events.md#input-events).

`rb.input` is updated before handlers and binds run. In a `down` handler or bind
callback the pressed key already reads as held. In an `up` handler or a bind's
`release` it already reads as released, so `rb.input.duration` returns `0`
there. To time a press, use the `up` handler's `duration_ms`, or record
`rb.system.time()` in the bind callback and compare in `release`. A key another
device still holds keeps reading as held.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.