Platform SDK: DirectX |
If you are using the joystick in foreground mode (see Cooperative Levels), you might lose the device when the focus shifts to another application.
You should check for the DIERR_INPUTLOST return value from the IDirectInputDevice7::GetDeviceData or the IDirectInputDevice7::GetDeviceState method and attempt to reacquire the joystick, if necessary. (See Acquiring Devices.)
Note You should not attempt to reacquire the joystick on getting a DIERR_NOTACQUIRED error. If you do, you could get caught in an infinite loop: acquisition would fail, you would get another DIERR_NOTACQUIRED error, and so on.
Because access to the joystick is not lost except when your application moves to the background—unlike the mouse and keyboard, the joystick is never used by the Windows system—an alternative method is to reacquire the device in response to a WM_ACTIVATE message.
You should check for the DIERR_INPUTLOST return value from the DirectInputDevice.GetDeviceData or the DirectInputDevice.GetDeviceStateKeyboard method and attempt to reacquire the keyboard, if necessary. (See Acquiring Devices.)
Note You should not attempt to reacquire the keyboard on getting a DIERR_NOTACQUIRED error. If you do, you could get caught in an infinite loop: acquisition would fail, you would get another DIERR_NOTACQUIRED error, and so on.