Game Development Reference
In-Depth Information
_device = new Device(SystemGuid.Mouse);
_device.SetDataFormat(DeviceDataFormat.Mouse);
}
catch (InputException)
{
return false;
}
You must also specify the cooperative level for DirectInput devices. The different
flags are described in Table 28.1.
Table 28.1 DirectInput Device Cooperative Level Flags
Flag Description
Exclusive This flag means that we want priority for control of the device.
NonExclusive This flag means that we do not need priority for control of the device.
Foreground This flag means that we only want data from the device if the window passed
into the SetCooperativeLevel method has focus.
Background This flag means that we always want data from the device.
NoWindowsKey This flag is used to ignore the Windows logo key, and is generally used in full
screen mode to prevent interruptions.
We always want data and we do not want to stall other applications using the input
devices, so we use the NonExclusive | Background level.
_device.SetCooperativeLevel(_context,
CooperativeLevelFlags.NonExclusive |
CooperativeLevelFlags.Background);
_device.SetEventNotification(_eventTrigger);
Acquire();
return true;
}
The polling thread runs in a loop, and each cycle is executed when the mouse is
moved. A cycle polls the mouse device to update the cached state information, and
then the callback method is fired. The callback method is registered by the con-
sumer of the component, and can be used to update the user interface or calculate
a 3D camera, for example.
Search Nedrilad ::




Custom Search