DirectInput introduction

xiaoxiao2021-03-06  68

DirectInput introduction

Microsoft DirectInput is an application interface (API) of an input device, including mouse, keyboard, joystick, and other game controllers, such as power feedback (input / output) devices.

This section mainly makes a brief description of DirectInput and introduces how to create a DirectInput application. This section mainly includes the following:

DirectInput's ability starts from DirectInput

To fully understand DirectInput work, please refer to "Understanding DirectInput".

To learn the DirectInput API programming, you can refer to the following sections:

Application DirectInput DirectInput C / C tutorial

DirectInput's ability

In addition to supporting device services that Microsoft Win32 APIs do not support, DirectInput can also provide a faster access method than Microsoft Windows messages in a way directly to Microsoft Windows messages.

Even if the application is in the background, DirectInput can also apply input device data. Similarly, all types of input devices provide full support, including force feedback controllers.

With an Action mapping, the application does not need to know what type of device that is specifically used, you can get input data.

DirectInput expansion services and improved performance, great for games, simulations, and real-time sessions.

However, DirectInput does not provide more advantages for applications that use keyboard for text input or mouse navigation. For more information, you can refer to "Windows Interaction".

Starting from DirectInput

This section applies DirectInput overview how to create a simple program.

For more details and examples, you can refer to the "Application DirectInput and DirectInput C / C Tutorials".

Note: To learn about DirectInput, you must understand the following terms:

DirectInput object: Total DirectInput interface device: Keyboard, mouse, joystick and other device DirectInputDevice object: used to represent a keyboard, mouse, joystick, or other input device object: to indicate a button on the DirectInput device object, buttons , Triggers, etc., also known as device object instances.

A simple application of a DirectInput can be implemented by the following steps, so that the program can take over to determine the device object (buttons, axis (axes), etc.) data items:

Create a DirectInput object. Use this object to enumerate your device and create a DirectInput device object. Enumerate the equipment. This step can be skipped if you only need to use only mouse or keyboard. If you need to determine if there are other input devices in the system, you need to use DirectInput to list. When DirectInput finds a device you set, you can check the ability of the device, and you can also get a unique identifier that can be created by identifying the device object. Create the DirectInputDevice object of the device you want to use. Here you need to use the identifier in the previous step. For system mouse or keyboard, you can use a standard global unique identifier (GUID). Set the device information. For each device, you first need to set its collaborative level, that is, what is the device shared with the system or other application; then it is used to identify the data format of the device object in the packet, such as buttons or Axes; if you need to get buffer data - that is, preferring to event rather than status - then you also need to set the buffer size. In addition, in this step, you can get information about the device and thus the behavior of the application. Finally, you can also set some attribute values, such as the range of return values ​​of the game rod axis. Get the equipment. This step tells the DirectInput device ready to receive data. retrieve data. After a period of time, after a message is loop or drawing the cycle, the current state of each device can be obtained or an event record since the last detection. If you need, as long as an event occurs, DirectInput can notify you. The corresponding operation is performed according to the data. The application can respond to the status of the button, the axis, or the incident generated when the button is pressed, released. Close DirectInput. Before exiting, the application should no longer need all devices, remember to release them, then release the DirectInput object. The above is not the only way to achieve DirectInput, in order to utilize a variety of input devices in the future, you can provide a simplified configuration to users, and you can use action mapping.

To set an action mapping of a device, let DirectInput determine what device objects are used each application. For example, in the racing game (Racing Game) is usually used with Y-axis control speed. Instead, you can create an AXIS_THROTTLE operation, and let DirectInput put the operation to the most suitable axis on the device. When you receive a message, you need to identify them through a federated operation, not the device object.

For more information, please refer to the operation mapping.

Original: Introduction to Directiput, DirectX SDK

© 2004 Microsoft Corporation. All Rights Reserved.

Translation: Room3rd@hotmail.com, 2004-11-27

转载请注明原文地址:https://www.9cbs.com/read-87103.html

New Post(0)