Class

# GameInputManager

<div class="rst-class">

forsearch

</div>

Gaming

<div class="rst-class">

forsearch

</div>

Hardware

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Manages all the game input devices connected to the computer.

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                              | Parameters                                        | Returns                                            | Shared |
|---------------------------------------------------|---------------------------------------------------|----------------------------------------------------|--------|
| `Device<gameinputmanager.device>`                 | deviceIndex As `Integer</api/data_types/integer>` | `GameInputDevice</api/hardware/gameinputdevice>`   |        |
| `DeviceCount<gameinputmanager.devicecount>`       |                                                   | `Integer</api/data_types/integer>`                 |        |
| `WaitForElement<gameinputmanager.waitforelement>` | timeOut As `Single</api/data_types/single>`       | `GameInputElement</api/hardware/gameinputelement>` |        |

## Method descriptions

<div id="gameinputmanager.device">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

GameInputManager.Device

**Device**(deviceIndex As `Integer</api/data_types/integer>`) As `GameInputDevice</api/hardware/gameinputdevice>`

> Gets the device at the specified *deviceIndex* and returns a `GameInputDevice</api/hardware/gameinputdevice>`.
>
> This example gets the list of all the devices on the user's computer and displays them in a `ListBox</api/user_interface/desktop/desktoplistbox>`. mManager is a `GameInputDevice</api/hardware/gameinputdevice>` instance that has been added to the window.
>
> ``` xojo
> Var gCount, i As Integer
>
> If mManager = Nil Then
>   mManager = New GameInputManager
> End If
>
> gCount = mManager.DeviceCount - 1
>
> For i = 0 To gCount
>   Listbox1.AddRow(mManager.Device(i).Name)
> Next
> ```

<div id="gameinputmanager.devicecount">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

GameInputManager.DeviceCount

**DeviceCount** As `Integer</api/data_types/integer>`

> Returns as an `Integer</api/data_types/integer>` the number of input devices.
>
> This example gets the list of all the devices on the user&lsquo;s computer and displays them in a `ListBox</api/user_interface/desktop/desktoplistbox>`. mManager is a `GameInputDevice</api/hardware/gameinputdevice>` instance that has been added to the window.
>
> ``` xojo
> Var gCount, i As Integer
>
> If mManager = Nil Then
>   mManager = New GameInputManager
> End If
>
> gCount = mManager.DeviceCount - 1
>
> For i = 0 To gCount
>   Listbox1.AddRow(mManager.Device(i).Name)
> Next
> ```

<div id="gameinputmanager.waitforelement">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

GameInputManager.WaitForElement

**WaitForElement**(timeOut As `Single</api/data_types/single>`) As `GameInputElement</api/hardware/gameinputelement>`

> Returns the `GameInputElement</api/hardware/gameinputelement>` the user pressed. It waits for an element to change on any input device. *timeOut* is in seconds.
>
> The following example determines which element the user is using as the Fire key. It assumes that there is a global property, mManager as <span class="title-ref">GameInputManager</span>, and mFireButton as a `GameInputElement</api/hardware/gameinputelement>`.
>
> ``` xojo
> 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
> ```

## Notes

Use the <span class="title-ref">GameInputManager</span>, `GameInputDevice</api/hardware/gameinputdevice>`, and `GameInputElement</api/hardware/gameinputelement>` classes to manage input devices, such as joysticks, used for gaming. Each such device is a `GameInputDevice</api/hardware/gameinputdevice>` and each of a device's controls, such as its buttons and joystick axes, is a `GameInputElement</api/hardware/gameinputelement>`.

To support game input devices, create a single instance of the <span class="title-ref">GameInputManager</span> class. Use the Device and DeviceCount properties of the <span class="title-ref">GameInputManager</span> class to get the list of input devices. Each such device is a `GameInputDevice</api/hardware/gameinputdevice>` and it has one or more `GameInputElements</api/hardware/gameinputelement>`, 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</api/hardware/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:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Windows

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### macOS

Support is built-in to macOS applications.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Linux

The <span class="title-ref">GameInputManager</span> class is not supported on Linux.

## Sample code

The following example determines which element the user is using as the Fire key. It assumes that there is a global property, mManager as <span class="title-ref">GameInputManager</span>, and mFireButton as a `GameInputElement</api/hardware/gameinputelement>`.

``` xojo
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:

``` xojo
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</api/hardware/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</api/user_interface/desktop/desktoppopupmenu>` control. It also assumes a global property mManager as <span class="title-ref">GameInputManager</span>.

``` xojo
Var deviceCount As Integer

If mManager = Nil Then
  mManager = New GameInputManager
End If

deviceCount = mManager.DeviceCount - 1

For i As Integer = 0 To deviceCount
  PopupMenu1.AddRow(mManager.Device(i).Name)
Next
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following example loads the names of the elements of a device into a `PopupMenu</api/user_interface/desktop/desktoppopupmenu>` control called ElementPop. It is in the SelectionChanged event handler of the `PopupMenu</api/user_interface/desktop/desktoppopupmenu>` containing the list of devices.

``` xojo
ElementPop.RemoveAllRows

Var device As GameInputDevice
device = mManager.Device(Me.SelectedRowIndex) ' selected device in Device popup

If device <> Nil Then

  Var elementCount As Integer = device.ElementCount - 1

  For i As Integer = 0 To elementCount
    ElementPop.AddRow(device.Element(i).Name)
  Next

End If

mElement = Nil
```

## Compatibility

|                       |                |
|-----------------------|----------------|
| **Project Types**     | Desktop        |
| **Operating Systems** | macOS, Windows |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `GameInputDevice</api/hardware/gameinputdevice>`, `GameInputElement</api/hardware/gameinputelement>` classes.

</div>
