# Input State

These global variables provide information about the current state of input devices like mouse, keyboard, and gamepads.

## Mouse Variables

| Variable       | Type    | Description                                                         |
| -------------- | ------- | ------------------------------------------------------------------- |
| `mouse_down`   | Boolean | Whether any mouse button is currently pressed                       |
| `mouse_ondown` | Boolean | Whether any mouse button was just pressed (true for only one frame) |
| `mouse_left`   | Boolean | Whether the left mouse button is currently pressed                  |
| `mouse_middle` | Boolean | Whether the middle mouse button is currently pressed                |
| `mouse_right`  | Boolean | Whether the right mouse button is currently pressed                 |
| `mouse_moving` | Boolean | Whether the mouse cursor has changed positions since last frame.    |
| `cursor`       | String  | The current mouse cursor style (e.g., "default", "pointer")         |

## Keyboard Variables

| Variable      | Type  | Description                                     |
| ------------- | ----- | ----------------------------------------------- |
| `all_pressed` | Array | Array of all keys currently being pressed       |
| `all_hit`     | Array | Array of keys just pressed in the current frame |

## Scroll Variables

| Variable            | Type   | Description                                                     |
| ------------------- | ------ | --------------------------------------------------------------- |
| `scroll_velocity`   | Number | The current vertical scroll velocity                            |
| `scroll.x.velocity` | Number | The current horizontal scroll velocity                          |
| `scroll.y.velocity` | Number | The current vertical scroll velocity (same as scroll\_velocity) |
| `scroll.multiplier` | Number | The user's scroll speed multiplier preference                   |

## Other Variables

| Variable       | Type     | Description                                                                                                                                |
| -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `picker_color` | String   | Currently selected color in the [color picker](https://github.com/Mistium/OSL-Docs/blob/main/commands/basics/color-picker.md) (hex format) |
| `getGamepads`  | Function | Function to get information about connected gamepads                                                                                       |

## Examples

```javascript
// Check for mouse input
if mouse_down (
  log "Mouse is being held down"
)

if mouse_left (
  log "Left mouse button is pressed"
)

// Check for keyboard input
if pressed == "Enter" (
  log "Enter key was just pressed"
)

// Check if a specific key is being held
if all_pressed.contains("shift") (
  log "Shift is being held down"
)

// Respond to scroll input
if scroll_velocity > 0 (
  log "User is scrolling down"
) else if scroll_velocity < 0 (
  log "User is scrolling up"
)

// Change cursor style
cursor = "pointer" // Changes mouse cursor to a pointer

// Get gamepad information
gamepads = getGamepads()
if gamepads.len > 0 (
  log "Gamepad connected: " + gamepads[0].id
)
```


---

# Agent Instructions: 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:

```
GET https://osl.mistium.com/global-variables/input-state.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
