Step 4: Setting the Keyboard Behavior
Microsoft DirectX 9.0 SDK Update (October 2004)

Step 4: Setting the Keyboard Behavior


Before your application can gain access to the keyboard, it must set the device's behavior using the IDirectInputDevice8::SetCooperativeLevel method, as shown in Tutorial 1 Samples. This method accepts the handle to the window to be associated with the device and a combination of flags that determine the cooperative level. In this case the application is requesting foreground, nonexclusive access.

The following example attempts to set the device's cooperative level. If this fails, it calls the DI_Term application-defined sample function to deallocate existing Microsoft DirectInput objects, if any.

// Set the cooperative level 

hr = g_lpDIDevice->SetCooperativeLevel(g_hwndMain, 
		DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); 

 if FAILED(hr) { 
    DI_Term(); 
    return FALSE; 
} 

After setting the keyboard behavior, go to Step 5: Gaining Access to the Keyboard.



© 2004 Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center.