Object

GameInputManager Class

Manages all the game input devices connected to the computer.

Methods
Device
DeviceCount
WaitForElement

# Notes

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.

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).

## Mac "classic"

Only the keyboard and the main (or only) mouse button are supported.

## Mac OS X

The keyboard and mouse button are supported, as on Mac OS 8-9. In addition, you need to install the file "HID.Bundle" in the same folder as your application to access other game input devices, such as joysticks.

## Linux

The GameInputManager class is not supported on Linux.

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.

# Examples

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.WaitForInput(3)
If mFireButton <> Nil then
MsgBox "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.

Dim gCount,i as Integer
If mManager= Nil then
mManager= New GameInputManager
end if
gCount=mManager.DeviceCount
For i =0 to gCount-1
PopupMenu1.Addrow mManager.device(i).Name
Next

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.

Dim i, Maxi As Integer
Dim device As GameInputDevice
ElementPop.DeleteAllRows
Device = mManager.Device( Me.ListIndex) //selected device in Device popup
If Device <> Nil then
Maxi = Device.ElementCount
For i = 0 to Maxi-1
ElementPop.AddRow Device.Element(i).Name
next
end if
mElement = Nil

# See Also

GameInputDevice, GameInputElement classes.