The SetDataFormat function specifies which data format will be used.
The single parameter to this function specifies the device type. For the keyboard, you want to pass the value of c_dfDIKeyboard as this parameter. The constant for a mouse would be c_dfDIMouse. Here, then, is a sample function call:
HRESULT result = dikeyboard->SetDataFormat(&c_dfDIKeyboard);
Note that you do not need to define c_dfDIKeyboard yourself; it is defined in dinput.h.