Kōtuku
  • Gallery
  • API
  • Wiki
  • GitHub
    • Audio
    • Config
    • Core
    • Display
    • Document
    • Font
    • HTTP
    • Network
    • Regex
    • SVG
    • Tiri
    • Vector
    • XML
    • XQuery
    • XRandR
      • Audio
      • MP3
      • Sound
      • File
      • MetaClass
      • Module
      • StorageDevice
      • Task
      • Thread
      • Time
      • Compression
      • CompressedStream
      • Config
      • LZMAStream
      • Script
      • Tiri
      • XML
      • XQuery
      • Controller
      • BlurFX
      • ColourFX
      • CompositeFX
      • ConvolveFX
      • DisplacementFX
      • FilterEffect
      • FloodFX
      • ImageFX
      • LightingFX
      • MergeFX
      • MorphologyFX
      • OffsetFX
      • RemapFX
      • SourceFX
      • TurbulenceFX
      • WaveFunctionFX
      • Scintilla
      • Bitmap
      • Clipboard
      • Display
      • Document
      • Font
      • Image
      • Pointer
      • Surface
      • SVG
      • ClientSocket
      • HTTP
      • NetClient
      • NetLookup
      • NetServer
      • NetSocket
      • Proxy
      • Gradient
      • GradientConic
      • GradientContour
      • GradientDiamond
      • GradientDiffusion
      • GradientDistal
      • GradientGouraud
      • GradientLinear
      • GradientMesh
      • GradientRadial
      • GradientVoronoi
      • Vector
      • VectorClip
      • VectorColour
      • VectorEllipse
      • VectorFilter
      • VectorGradient
      • VectorGroup
      • VectorImage
      • VectorPath
      • VectorPattern
      • VectorPolygon
      • VectorRectangle
      • VectorScene
      • VectorShape
      • VectorSpiral
      • VectorText
      • VectorTransition
      • VectorViewport
      • VectorWave
      • Linux Builds
      • Windows Builds
      • Customising Your Build
      • Kōtuku Objects
      • Kōtuku In Depth
      • Kōtuku Design Patterns
      • Coding With AI
      • Regex Manual
      • XML Comparisons
      • Tiri Reference Manual
      • Config API
      • Defer Syntax
      • GUI API
      • HTTP Server API
      • I/O API
      • JSON API
      • OAuth API
      • Options API
      • Proxy Server API
      • Tempus API
      • URL API
      • VFX API
      • Widgets
      • RIPL Reference Manual
      • Origo
      • Flute / Unit Testing
      • Tuku
      • Embedded Document Format
      • TDL Reference Manual
      • TDL Tools
      • Action Reference Manual
      • System Error Codes

Controller Class

Provides support for reading state-based game controllers.

Use the Controller class to read the state of game controllers that are recognised by the operating system.

Unlike analog devices that stream input commands (e.g. mice), gamepad controllers maintain a state that can be read at any time. The controller state is normally read at least once per frame, which can be achieved in a program's inner loop, or in a separate timer.

On Linux, controllers are read through the /dev/input/js* joystick API. The user running the application must have read access to these device nodes.

Controller input management is governed by the Display class. The GRAB_CONTROLLERS flag should be defined in the active Display⇒Flags field in order to ensure that controller input can be received from the host. Failure to do so may mean that the Controller object works inconsistently across different systems.

Structure

The Controller class consists of the following fields:

Access
NameTypeComment
 ButtonsCONButton values expressed as bit-fields.
NameDescription
CON::DPAD_DOWNDirectional pad down.
CON::DPAD_LEFTDirectional pad left.
CON::DPAD_RIGHTDirectional pad right.
CON::DPAD_UPDirectional pad up.
CON::GAMEPAD_EEast button (B)
CON::GAMEPAD_NNorth button (Y)
CON::GAMEPAD_SSouth button (A)
CON::GAMEPAD_WWest button (X)
CON::LEFT_BUMPER_1Gamepad left-hand bumper 1 (top, primary).
CON::LEFT_BUMPER_2Gamepad left-hand bumper 2 (lower).
CON::LEFT_THUMBLeft thumb stick depressed.
CON::RIGHT_BUMPER_1Gamepad right-hand bumper 1 (top, primary).
CON::RIGHT_BUMPER_2Gamepad right-hand bumper 2 (lower).
CON::RIGHT_THUMBRight thumb stick depressed.
CON::SELECTGamepad select or back button.
CON::STARTGamepad start button.
 LeftStickXDOUBLELeft analog stick value for X axis, between -1.0 and 1.0.
 LeftStickYDOUBLELeft analog stick value for Y axis, between -1.0 and 1.0.
 LeftTriggerDOUBLELeft trigger value between 0.0 and 1.0.
 PortINTThe port number assigned to the controller.

Set the port number to choose the controller that will be queried for state changes. The default of -1 is used to indicate the primary (first available) controller. Fixed port numbers start from zero. There is no guarantee that the existence of a port means that a controller is connected to it.

On Windows, XInput user indices occupy ports zero through three. DirectInput controllers use stable slots from four through 31 while connected. This reservation means that a DirectInput-only controller can produce a TotalPorts value of five while ports zero through three remain disconnected.

It is acceptable to set the port number post-initialisation, so multiple controllers can be queried through one interface at the cost of overwriting the previous state. Enumeration for the discovery of controllers can be achieved by calling Query() for each port and checking for ERR::Okay.

Read TotalPorts to get the maximum number of controller ports.

 RightStickXDOUBLERight analog stick value for X axis, between -1.0 and 1.0.
 RightStickYDOUBLERight analog stick value for Y axis, between -1.0 and 1.0.
 RightTriggerDOUBLERight trigger value between 0.0 and 1.0.
 TotalPortsINTReports the number of controller ports that should be scanned.

Port values range from zero to TotalPorts - 1. Some platforms, including Linux and Windows, may expose sparse controller indices, so an individual port in that range can fail to query if its device is not currently connected. Windows DirectInput mappings support two sticks, two triggers, the first POV hat and the first 12 common gamepad buttons. Additional or specialist controls are ignored.

Actions

The following actions are currently supported:

QueryGet the current controller state.
ERR acQuery(*Object)

Query will update the controller field values with the state of the controller connected to the specified port. On failure, all axis and button fields are cleared while Port is preserved. Repeated calls to Query() return ERR::Disconnected until a controller is connected to the selected port, or any port when Port is -1.

Error Codes
OkayOperation successful.
ArgsInvalid arguments passed to function
NoSupportThe host does not support controller input.
OutOfRangeThe port number is outside of acceptable range.
AccessObjectAttempting to lock an object failed
NotInitialisedController access is not enabled on a suitable display.
SystemCallA call to the host system failed.
DisconnectedNo controller is connected to the specified port.
Controller class documentation © Paul Manias © 2003-2026

CON Type

Gamepad controller buttons.

NameDescription
CON::DPAD_DOWNDirectional pad down.
CON::DPAD_LEFTDirectional pad left.
CON::DPAD_RIGHTDirectional pad right.
CON::DPAD_UPDirectional pad up.
CON::GAMEPAD_EEast button (B)
CON::GAMEPAD_NNorth button (Y)
CON::GAMEPAD_SSouth button (A)
CON::GAMEPAD_WWest button (X)
CON::LEFT_BUMPER_1Gamepad left-hand bumper 1 (top, primary).
CON::LEFT_BUMPER_2Gamepad left-hand bumper 2 (lower).
CON::LEFT_THUMBLeft thumb stick depressed.
CON::RIGHT_BUMPER_1Gamepad right-hand bumper 1 (top, primary).
CON::RIGHT_BUMPER_2Gamepad right-hand bumper 2 (lower).
CON::RIGHT_THUMBRight thumb stick depressed.
CON::SELECTGamepad select or back button.
CON::STARTGamepad start button.
Controller module documentation © Paul Manias © 2003-2026