DIK_RWIN Right-side Windows key
DIK_APPS Application key
Cooperative Levels
DirectInput devices have a concept of a cooperative level, since they are
shared by all applications using the system. Setting the cooperative level is
the first thing that you should do upon successful creation of an
IDirectInputDevice8 interface. The call to set the cooperative level is:
HRESULT IDirectInputDevice8::SetCooperativeLevel(
HWND hwnd,
DWORD dwFlags
);
hwnd Handle to the window of the application that created the object.
dwFlags A set of flags describing the cooperative level desired. Can be a combination of
the following:
DISCL_BACKGROUND—When this flag is set, the application may acquire
the device at any time, even if it is not the currently active application.
DISCL_EXCLUSIVE—Application requests exclusive access to the input
device. This prevents other applications from simultaneously using the device
(for example, Windows itself). If the mouse device is set to exclusive mode,
Windows stops sending mouse messages and the cursor disappears.
DISCL_FOREGROUND—When this flag is set, the device is automatically
unacquired when the window moves to the background. It can only be
reacquired when the application moves to the foreground.
DISCL_NONEXCLUSIVE—Application requests non-exclusive access to the
input device. This way it doesn’t interfere with the other applications that are
simultaneously using the device (for example, Windows itself).
DISCL_NOWINKEY—Disables the use of the Windows key. This prevents
the user from accidentally being knocked out of an exclusive application by
pressing the Windows key.
All devices must set either DISCL_FOREGROUND or DISCL_BACK
-
GROUND (but not both), as well as either DISCL_EXCLUSIVE or DISCL_
NONEXCLUSIVE (but not both).
Application Focus and Devices
If you ever can’t get the device state from a device, chances are access to it
has been lost. For example, when the application doesn’t have focus you
can’t grab the state of the keyboard. The application class will automati
-
cally detect when it loses focus and stop the input code from polling the
devices until focus is regained. When you get focus, you need to reacquire
the device before you can start requesting its state. That is done using the
Chapter 3: Input and Sound n 73

Get Advanced 3D Game Programming with DirectX 10.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.