Mouse Input
XNA provides a Mouse class to interact with the
mouse that behaves very similarly to the Keyboard
class. The Mouse class also has a GetState method that you can use to get data from the
mouse in the form of a MouseState struct. The
Mouse class also has another method worthy of
note: void SetPosition(int x, int y). This method
will—you guessed it—allow you to set the position of the mouse. This position is
relative to the upper-left corner of the game window.
The MouseState struct has several properties
that will help you understand what is happening with the mouse at the particular
moment in time when you called GetState. These
properties are detailed in Table 3-2.
Table 3-2. Important properties of the MouseState struct
|
Property |
Type |
Description |
|---|---|---|
|
|
|
Returns the state of the left mouse button. |
|
|
|
Returns the state of the middle mouse button. |
|
|
|
Returns the state of the right mouse button. |
|
|
|
Returns the total accumulated movement of the scroll wheel since the game started. To find out how much the scroll wheel has moved, compare this value to the previous frame's scroll wheel value. |
|
|
|
Returns the value of the horizontal position of the mouse in relation to the upper-left corner of the game window. If the mouse is to the left of the game window, the value is negative. If the mouse is to the right of the game window, the value is greater than the width ... |