Game Development Reference
In-Depth Information
Asynchronous Mouse Polling
The first step is to include and reference the appropriate namespaces. You should
add a reference to Microsoft.DirectX and Microsoft.DirectX.DirectInput and use
the following namespaces.
using System;
using System.Threading;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectInput;
The following class encapsulates all the nitty gritty details of using DirectInput for
mouse polling. After instantiation, the Initialize method is executed to create the
mouse input device and to spawn the asynchronous polling thread.
public class AsynchronousMouse : IDisposable
{
The Device object is used to manage Microsoft DirectInput devices and associated
properties, specify behavior, manage force-feedback effects, interact with the device's
control panel, and perform device initialization.
private Device _device = null;
private Thread _threadData = null;
private AutoResetEvent _eventTrigger = null;
private byte[] _buttons;
private int _x;
private int _y;
private int _z;
private System.Windows.Forms.Form _context;
public delegate void MovementDelegate(int x,
int y,
int z,
bool left,
bool middle,
bool right);
private delegate void PollTriggerDelegate();
public event MovementDelegate MouseMovement;
Search Nedrilad ::




Custom Search