Documentation/Features/Input Handling

Input Handling

Process keyboard, mouse, and touch input in your games.

Input System

The InputSystem handles all user input in StarForge, including keyboard, mouse, touch, and gamepad.

Getting the InputSystem

local inputSystem = engine:GetSystem("InputSystem")

Input Events

The InputSystem provides three main events:

  • InputBegan - Fires when an input starts (key press, mouse down)
  • InputChanged - Fires when an ongoing input changes (mouse move)
  • InputEnded - Fires when an input ends (key release, mouse up)
-- Handle key presses
inputSystem.InputBegan:Connect(function(input)
    if input.Type == InputType.Keyboard then
        if input.Key == KeyCode.Space then
            player:Jump()
        elseif input.Key == KeyCode.W then
            player:MoveForward()
        end
    end
end)

-- Handle mouse movement
inputSystem.InputChanged:Connect(function(input)
    if input.Type == InputType.Mouse then
        local delta = input.Delta
        camera:Rotate(delta.X, delta.Y)
    end
end)

Input Object Properties

Each Input object contains:

  • State - Current state (Begin, Change, End)
  • Type - Input type (Keyboard, Mouse, Touch)
  • Key - Key or button code
  • Position - Position for mouse/touch inputs
  • Delta - Change since last event

Checking Input State

-- Check if a key is currently held
if inputSystem:IsKeyDown(KeyCode.Shift) then
    player.Speed = player.RunSpeed
else
    player.Speed = player.WalkSpeed
end