From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from Object)

Manages all the game input devices connected to the computer.

Device WaitForElement


Use the GameInputManager, GameInputDevice, and GameInputElement classes to manage input devices, such as joysticks, used for gaming. Each such device is a GameInputDevice and each of a device's controls, such as its buttons and joystick axes, is a GameInputElement.

To support game input devices, create a single instance of the GameInputManager class. Use the Device and DeviceCount properties of the GameInputManager class to get the list of input devices. Each such device is a GameInputDevice and it has one or more GameInputElements, such as a Fire button, scroll wheel, joystick axes, and so forth. You can get the list of devices by the Name property of the GameInputDevice class and each device's list of elements.

Use the WaitForElement method to get input from any element.

The system requirements for each platform are as follows:


DirectX 8 (or above) must be installed in order to access any input devices (including the keyboard).


Support is built-in to macOS applications.


The GameInputManager class is not supported on Linux.


The following example determines which element the user is using as the Fire key. It assumes that there is a global property, mManager as GameInputManager, and mFireButton as a GameInputElement.

If mManager = Nil Then
mManager = New GameInputManager
End If

mFireButton = mManager.WaitForElement(3)
If mFireButton <> Nil Then
MessageBox("You're using " + mFireButton.Name + " as the Fire button.")
End If

The following example handles the Fire button:

If mFireButton <> Nil And mFireButton.Value <> 0 Then
// take action here
End If

The first example shows how you can allow the user to configure his game devices and how actions on those devices will correspond to your game's actions. The second example shows how you can use a GameInputElement to determine whether it is time to do its corresponding game action. Note that in the second example, we are polling for the current state of that element (instead of getting an old value out of it).

The following example loads the names of the input devices into a PopupMenu control. It also assumes a global property mManager as GameInputManager.

Var deviceCount As Integer
If mManager = Nil Then
mManager = New GameInputManager
End If

deviceCount = mManager.DeviceCount
For i As Integer = 0 To deviceCount - 1

The following example loads the names of the elements of a device into a PopupMenu control called ElementPop. It is in the Change event handler of the PopupMenu containing the list of devices.

Var device As GameInputDevice

device = mManager.Device(Me.SelectedIndex) // selected device in Device popup
If device <> Nil Then
Var elementCount As Integer = device.ElementCount
For i As Integer = 0 To elementCount - 1
End If

mElement = Nil

See Also

GameInputDevice, GameInputElement classes.