After retrieving an IDirectInputDevice8 Interface 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 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) { DI_Term(); return FALSE; }
After setting the keyboard data format, go to Step 4: Setting the Keyboard Behavior.