Class
GameInputManager
Description
Manages all the game input devices connected to the computer.
Method descriptions
GameInputManager.Device
Device(Index As Integer) As GameInputDevice
Gets the device at the specified index and returns a GameInputDevice.
This example gets the list of all the devices on the user's computer and displays them in a ListBox. mManager is a GameInputDevice instance that has been added to the window.
Var gCount, i As Integer
If mManager=Nil Then
mManager=New GameInputManager
End If
gCount = mManager.DeviceCount
For i = 0 To gCount-1
Listbox1.AddRow(mManager.Device(i).Name)
Next
GameInputManager.DeviceCount
DeviceCount As Integer
Returns as an Integer the number of input devices.
This example gets the list of all the devices on the user‘s computer and displays them in a ListBox. mManager is a GameInputDevice instance that has been added to the window.
Var gCount, i As Integer
If mManager=Nil Then
mManager=New GameInputManager
End If
gCount = mManager.DeviceCount
For i = 0 To gCount-1
Listbox1.AddRow(mManager.Device(i).Name)
Next
GameInputManager.WaitForElement
WaitForElement(timeout As Single) As GameInputElement
Returns the 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 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
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.
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:
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 GameInputManager 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 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
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 SelectionChanged event handler of the PopupMenu containing the list of devices.
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
For i As Integer = 0 To elementCount - 1
ElementPop.AddRow(device.Element(i).Name)
Next
End If
mElement = Nil
Compatibility
All project types on all supported operating systems.
See also
Object parent class; GameInputDevice, GameInputElement classes.