Skip to content

Gamepad Module

STBrian edited this page Nov 9, 2026 · 1 revision

The Gamepad submodule handles user input from the Nintendo 3DS physical buttons, Circle Pad, C-Stick, and touch screen. It also provides events that fire whenever keys are pressed, held, or released.

Events

Game.Gamepad.OnKeyPressed Fires on the frame a button is initially pressed down
Game.Gamepad.OnKeyDown Fires continuously every frame a button is held down
Game.Gamepad.OnKeyReleased Fires on the frame a button is released

Constants

Game.Gamepad.KeyCodes Bitmask constants for all 3DS buttons and directional inputs

Functions

Game.Gamepad.isPressed Checks if a key was pressed on this frame
Game.Gamepad.isDown Checks if a key is currently held down
Game.Gamepad.isReleased Checks if a key was released on this frame
Game.Gamepad.pressButton Simulates / injects a virtual button press
Game.Gamepad.getTouch Returns the current touch screen X and Y coordinates

Game.Gamepad.OnKeyPressed

Fires whenever one or more buttons are pressed. Passes the bitmask of currently pressed keys to the listener.

Game.Gamepad.OnKeyPressed:Connect(function(keys: integer)
end)

Example

Game.Gamepad.OnKeyPressed:Connect(function(keys)
    if bit32.btest(keys, Game.Gamepad.KeyCodes.X) then
        Core.Debug.message("X button was pressed!")
    end
end)

Game.Gamepad.OnKeyDown

Fires every frame while one or more buttons remain held down.

Game.Gamepad.OnKeyDown:Connect(function(keys: integer)
end)

Game.Gamepad.OnKeyReleased

Fires on the exact frame when one or more buttons are released.

Game.Gamepad.OnKeyReleased:Connect(function(keys: integer)
end)

Game.Gamepad.isPressed

Returns true if the specified key code was initially pressed during the current frame.

Game.Gamepad.isPressed(keycode: integer) -> boolean

Game.Gamepad.isDown

Returns true if the specified key code is held down.

Game.Gamepad.isDown(keycode: integer) -> boolean

Game.Gamepad.isReleased

Returns true if the specified key code was released on the current frame.

Game.Gamepad.isReleased(keycode: integer) -> boolean

Game.Gamepad.pressButton

Injects a virtual key press for the given keycode.

Game.Gamepad.pressButton(keycode: integer)

Game.Gamepad.getTouch

Reads the touch screen state and returns the current X and Y coordinates (px, py). Returns 0, 0 if the touch screen is not being touched.

Game.Gamepad.getTouch() -> number, number

Game.Gamepad.KeyCodes

Table containing bitmask constants for all inputs:

  • A: 1
  • B: 2
  • SELECT: 4
  • START: 8
  • DPADRIGHT: 16
  • DPADLEFT: 32
  • DPADUP: 64
  • DPADDOWN: 128
  • R: 256
  • L: 512
  • X: 1024
  • Y: 2048
  • ZL: 16384 (New 3DS only)
  • ZR: 32768 (New 3DS only)
  • TOUCHPAD: 1048576
  • CSTICKRIGHT: 16777216
  • CSTICKLEFT: 33554432
  • CSTICKUP: 67108864
  • CSTICKDOWN: 134217728
  • CPADRIGHT: 268435456
  • CPADLEFT: 536870912
  • CPADUP: 1073741824
  • CPADDOWN: 2147483648
  • UP: DPADUP or CPADUP
  • DOWN: DPADDOWN or CPADDOWN
  • LEFT: DPADLEFT or CPADLEFT
  • RIGHT: DPADRIGHT or CPADRIGHT
  • CPAD: Any Circle Pad direction
  • CSTICK: Any C-Stick direction

Clone this wiki locally