Game Development Reference
In-Depth Information
public delegate void ActionDelegate();
public event ActionDelegate KeyboardAction;
private KeyboardState _keyboardState;
public bool Initialize(System.Windows.Forms.Form context)
{
_context = context;
_threadData = new Thread(new ThreadStart(this.AsynchronousPolling));
_threadData.Start();
_eventTrigger = new AutoResetEvent(false);
try
{
_device = new Device(SystemGuid.Keyboard);
_device.SetDataFormat(DeviceDataFormat.Keyboard);
}
catch (InputException)
{
return false;
}
_device.SetCooperativeLevel(_context,
CooperativeLevelFlags.NonExclusive |
CooperativeLevelFlags.Background);
_device.SetEventNotification(_eventTrigger);
Acquire();
return true;
}
The following method is used to query the keyboard state to determine whether a
particular key is depressed. The keyboard state is cached each time the state
changes within the asynchronous polling thread.
public bool KeyDown(Key key)
{
if (_keyboardState != null && _keyboardState[key])
{
Search Nedrilad ::




Custom Search