Microsoft DirectX 9.0

Step 3: Setting the Keyboard Data Format

After retrieving an IDirectInputDevice8 pointer, your application must set the device's data format, as shown in Tutorial 1 Samples. For keyboards, this is a very simple task. Call the IDirectInputDevice8::SetDataFormat method, specifying the data format provided by Microsoft?DirectInput?in the c_dfDIKeyboard global variable.

The following example attempts to set the data format. If this fails, it calls the DI_Term sample function to deallocate existing DirectInput objects, if any.

hr = g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard); 

if FAILED(hr) { 
    return FALSE; 

After setting the keyboard data format, go to Step 4: Setting the Keyboard Behavior.

© 2002 Microsoft Corporation. All rights reserved.