List all avalaible game controlers (joysticks, gamepads).
Test their inputs: axes and buttons.
Using Castle Game Engine.
See https://castle-engine.io/controllers for the overview of using controllers in your own applications.
This example shows the public API to access game controllers:
-
Access them all using the
Controllerssingleton. -
Use
Controllers.Initializeto initialize the list of available game controllers. -
Receive game controllers button press / release using regular
TCastleUserInterface.Press/TCastleUserInterface.Release. Just like when you handle key and mouse events, see https://castle-engine.io/view_events . Just check forEventType = itGameControllerto detect game controller button events, like this:function TViewMain.Press(const Event: TInputPressRelease): Boolean; begin Result := inherited; if Result then Exit; // Handle game controller inputs, when Event.EventType = itGameController. // Check Event.Controller.Button and/or Event.Controller.Meaning . if (Event.EventType = itGameController) and (Event.Controller.Button = gbMenu) then begin // ... do something Exit(true); // handled end; if (Event.EventType = itGameController) and (Event.Controller.Meaning = gmConfirm) then begin // ... do something Exit(true); // handled end; end;
-
Observe the game controller axis in your view's
Updatemethod. Look at specific controller properties likeControllers[0].AxisLeft(2D axis)Controllers[0].AxisRight(2D axis)Controllers[0].AxisLeftTrigger(1D axis)Controllers[1].AxisRightTrigger(1D axis)
Compile by:
-
CGE editor. Just use menu items "Compile" or "Compile And Run".
-
Or use CGE command-line build tool. Run
castle-engine compilein this directory. -
Or use Lazarus. Open in Lazarus
game_controllers_demo_standalone.lpifile and compile / run from Lazarus. Make sure to first register CGE Lazarus packages. -
Or use Delphi. Open in Delphi
game_controllers_demo_standalone.dprojfile and compile / run from Delphi. See CGE and Delphi documentation for details.
