private Device _keyboardDevice, _mouseDevice;
public void InitializeDevice()
{
// Create the input device's.
_keyboardDevice = new Device(SystemGuid.Keyboard);
if (_keyboardDevice == null) return;
_mouseDevice = new Device(SystemGuid.Mouse);
if (_mouseDevice == null) return;
// Set the cooperative mode of this device.
_keyboardDevice.SetCooperativeLevel(null, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
_mouseDevice.SetCooperativeLevel(null, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
// Decide what data format we want the device to return.
_keyboardDevice.SetDataFormat(DeviceDataFormat.Keyboard);
_mouseDevice.SetDataFormat(DeviceDataFormat.Mouse);
// Aquire a connection to the physical device.
try
{
_keyboardDevice.Acquire();
_mouseDevice.Acquire();
}
catch (DirectXException)
{
_keyboardDevice = null;
_mouseDevice = null;
return;
}
}
You can then get the state of the keyboard using;
_keyboardDevice.GetCurrentKeyboardState();
And the mouse state using;
_mouseDevice.CurrentMouseState;
Sorry if thats not a very good explanation, I need sleep at the moment >.<.