Game Development Reference
In-Depth Information
Sample Usage
Using the two classes in this chapter is very easy. The following code is from the
example for this chapter on the Companion Web site. A callback is used to report
keyboard state changes, although AsynchronousKeyboard.KeyDown() can be called at
any time outside of
the callback. The Buttons, X, Y, Z properties of
the
AsynchronousMouse class can also be called outside of the callback too.
public partial class MainForm : Form
{
private AsynchronousMouse _mouse;
private AsynchronousKeyboard _keyboard;
public MainForm()
{
InitializeComponent();
_mouse = new AsynchronousMouse();
_mouse.MouseMovement +=
new AsynchronousMouse.MovementDelegate(MouseMovementCallback);
_keyboard = new AsynchronousKeyboard();
_keyboard.KeyboardAction +=
new AsynchronousKeyboard.ActionDelegate(KeyboardActionCallback);
}
void KeyboardActionCallback()
{
if (_keyboard.KeyDown(Microsoft.DirectX.DirectInput.Key.UpArrow))
{
UpArrowState.Text = “Down”;
}
else
{
UpArrowState.Text = “Up”;
}
if (_keyboard.KeyDown(Microsoft.DirectX.DirectInput.Key.DownArrow))
{
DownArrowState.Text = “Down”;
}
else
{
Search Nedrilad ::




Custom Search