After you have written a handler for the keyboard, the mouse is a bit easier to deal with because the DirectInput object will already exist. The code to initialize and poll the mouse is very similar to the keyboard code. First, define the mouse device variable:
LPDIRECTINPUTDEVICE8 dimouse;
Next, create the mouse device:
result = p_dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL);