Game Development Reference
In-Depth Information
beneath the mouse cursor and six other dots represent the button states. The top
three dots represent the held state of each button. Hold down a button and its
dot will light up; release the button and it will go black. The bottom three but-
tons represent the press state of the buttons. Each time a button is clicked, the
dot that represents it will toggle its color.
This is all that's required for basic mouse support. There is still more work that
can be done; for instance, detecting double-clicks of the mouse and having a way
to poll the scroll wheel, but for most games what has been covered so far will be
fine. The only remaining control method left to add is the keyboard.
Adding Keyboard Support
The keyboard is unlike the gamepad and the mouse because the method of in-
teracting with it depends on the situation. If you have a screen that asks the user
to enter his name, then you want a callback function that will tell you each
character pressed by the user. But if you are in the middle of a fighting game,
then you just want to be able to ask if a certain key has just been pressed; you
don't care about the rest of the keys. These are two different modes of interaction
and both are important and need to be supported.
The keyboard has an event-based system like the mouse. The form has OnKey-
Down and OnKeyUp events that can have delegates attached. Unfortunately,
these events ignore the arrow keys, and the arrow keys are very important in
games because they are often used to control movement. The Alt key is also
ignored as are a few other keys known collectively as the control keys. These keys
generally have some meaning in the form and are therefore hidden from general
use. Games need to use these keys so an alternative method of polling these keys
needs to be implemented.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Engine.Input
{
public class Keyboard
 
Search WWH ::




Custom Search