60 likes | 79 Views
Learn how to efficiently manage input devices like keyboard, mouse, and joystick using DirectInput in DirectX. Explore digital and analog controls, data buffering, and force feedback implementation.
E N D
GAM666 – Introduction To Game Programming DirectInput • DirectInput is the part of DirectX for managing input devices, such as keyboard, mouse and joystick • Supports both digital (buttons, D-pads) and analog (sliders, joystick axes, mouse axes) objects on a device • Can handle relative (e.g. mouse axes) and absolute (e.g. Joystick axes) analog objects • Data coming from the device can be buffered or immediate (in which case you poll the device) • Also controls force feedback joysticks (input device used for output)
GAM666 – Introduction To Game Programming DirectInput • Use DirectInput8Create() once to create a LPDIRECTINPUT8 COM object to control all subsequent DirectInput activity • Use its EnumDevices() function to enumerate available devices of the desired type, supplying your own function to handle each matching device (e.g. to find each one's GUID) • Use its CreateDevice() function to create a LPDIRECTINPUTDEVICE8 object to handle a specific device
GAM666 – Introduction To Game Programming DirectInput • Once you have a device, use its SetDataFormat() function to identify the structure that will be receiving data • Use its EnumObjects() function to find out about available buttons, axes, etc., supplying your own function to handle each object • Use its SetCooperativeLevel() function to identify how the device is to be shared with other running programs • Use its SetProperty() function to control how it works
GAM666 – Introduction To Game Programming DirectInput • Any absolute axis you have must be configured before use, setting the at least the following properties: • DIPROP_RANGE – the minimum and maximum values returned by the axis • DIPROP_DEADZONE – the percentage play (i.e. area where there is no change in input) at the middle of the axis (in hundreths of a percent) • DIPROP_SATURATION – the percentage play at the end of the axis
GAM666 – Introduction To Game Programming DirectInput • When specifying a device object such as an axis or a button, you can identify it by offset (i.e. position in the structure receiving the data) or by ID (available when enumerating device objects) • Before being able to read from the device it must be Acquire()ed • At any time the device might be taken from the program, in which case it must be Acquire()ed again
GAM666 – Introduction To Game Programming DirectInput • To poll an input device (immediate data)use the GetDeviceState() member function to fill up a structure containing a snapshot of the current state of the device • Some devices require calling Poll() before GetDeviceState() [it doesn't hurt to call it even if not necessary] • To get buffered data use the GetDeviceData() function to fill an array of object state changes