After creating the DirectInput object, your application must create the keyboard object - the device - and retrieve a pointer to an IDirectInputDevice8 Interface interface. The device performs most of the keyboard-related tasks, using the methods of the interface.
To do this your application must call the IDirectInput8::CreateDevice method, as shown in Tutorial 1 Samples. IDirectInput8::CreateDevice accepts three parameters.
The first parameter is the globally unique identifier (GUID) for the device being created. Because the system keyboard is used, your application should pass the GUID_SysKeyboard predefined global variable.
The second parameter is the address of a variable that is initialized with the interface pointer if the call succeeds.
The third parameter specifies the address of the controlling object's IUnknown interface for use in COM aggregation. Because most applications do not use aggregation, the value of this parameter is usually NULL.
The following example attempts to retrieve a pointer to an IDirectInputDevice8 Interface interface. If this fails, it calls the DI_Term application-defined sample function to deallocate existing DirectInput objects, if any.
Note In all the examples, g_lpdi is the initialized pointer to the DirectInput object.
HRESULT hr; LPDIRECTINPUTDEVICE8 g_lpDIDevice hr = g_lpDI->CreateDevice(GUID_SysKeyboard, &g_lpDIDevice, NULL); if FAILED(hr) { DI_Term(); return FALSE; }
After creating the DirectInput keyboard device, go to Step 3: Setting the Keyboard Data Format.