GameInputManager

From Xojo Documentation
Jump to: navigation, search

Class (inherits from Object)


Manages all the game input devices connected to the computer.


Methods
Device WaitForElement
DeviceCount


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.

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.WaitForElement(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.

Personal tools
Namespaces

Variants
Actions
Main
Content
Starting Out
Dig Deeper
More Help
Toolbox
About