Microsoft DirectX 8.1 (Visual Basic) |
As each device is enumerated, you can retrieve the default action map, make changes in the default map, and apply the final mappings.
Once the enumeration is complete, you can use the DirectInputEnumDevices8.GetItem method to obtain an instance of the DirectInputDeviceInstance8 class. DirectInputDeviceInstance8.GetGuidInstance enables the retrieval of the device GUID, which can in turn be passed to DirectInput8.CreateDevice. The resulting DirectInputDevice8 object can then be saved to a global variable for use in your application, and its methods can be used to get or set any properties of the device that you may wish to examine or change before building the action map.
To obtain the default action map for the device, call DirectInputDevice8.BuildActionMap. Microsoft® DirectInput® takes the list of virtual controls specified in your DIACTIONFORMAT type and attempts to map these to physical device objects, returning the results in the same type. You should examine the lHow member of each DIACTION element to determine whether the control was successfully mapped. If it was, you can also ascertain what criterion was used in choosing the object—for example, configuration by the user or by the device manufacturer.
You now have the option of changing the default mappings, although it is not recommended that you do so. After examining the lSemantic member of the DIACTION type to determine which device object was mapped to an action, you can change that value. For example, if an action is mapped to DIJOFS_BUTTON9, but you want that action to be mapped to the trigger button instead, change the value to DIJOFS_BUTTON0 before applying the action map.
When you are satisfied that the DIACTIONFORMAT type contains suitable mappings for the device, call DirectInputDevice8.SetActionMap. The value you assigned to the lAppData member of each DIACTION type now becomes bound to the control specified in the lSemantic member, which in turn is bound to a particular device object.
Repeat steps 1 through 4 for each device you want to use in your application. Suppose you want to map actions to both a joystick and the keyboard. In the racing-game example, the action defined in the game as eB_DRIVERVIEW was mapped to a keyboard key in the DIACTION array.
In that example, when BuildActionMap is called on any device that is not a keyboard, the lHow member of the DIACTION type for that element is set to DIAH_UNMAPPED. Continue examining the lHow member as each device in turn is enumerated, until a value other than DIAH_UNMAPPED is returned. This indicates that the device being currently mapped is a keyboard and the action has been successfully mapped to the requested key.
Even actions that have been successfully mapped can be mapped to another device. In the example, eB_UPSHIFT is given two DIACTION types.
As devices are successively enumerated, the eB_UPSHIFT action is mapped to a suitable button on one or more joysticks or other game controllers, and then again to the keyboard.
To show the user how actions have been mapped to devices, pass the DICD_DEFAULT flag to DirectInput8.ConfigureDevices. The property sheet for the device, containing a graphical representation of mappings, is displayed in view-only mode as in the following diagram. For more information on the mechanics of displaying the image, refer to the Using Action Mapping tutorial.
If the device manufacturer has not provided a device image, the mapping will be presented in text mode as in the following diagram.
Note Even if the cooperative level for the application is disabling the Microsoft® Windows® logo key passively through an exclusive cooperative level or actively through use of the DISCL_NOWINKEY flag, that key will be active while the default action mapping UI is displayed.
For more information about this property sheet, see User Configuration of the Device.