Reading input devices
The brick engine input system provides the programmer with access to the keyboard, joystick, and mouse. Input is based on the idea of a “virtual joystick” that consists of axes, hats, and buttons:
- Axes have a range from -127 to 127 and represent the analog axes on a joystick.
- Hats have a range from -1 to 1 and represent the four-direction hats present on some joysticks.
- Buttons are boolean values representing the various buttons on a joystick or gamepad.
In addition to the axes, hats, and buttons, there are several special keyboard keys that will also be read whenever any of the inputs is read.
Joysticks and the keyboard
If any joysticks are plugged into the computer, the brick engine will map them onto the virtual joysticks starting at number 0.
All keyboard input is mapped onto one of the eight virtual joysticks. Keypresses can be mapped onto the specific axes, hats, and buttons on any of these. A single keypress can also be mapped onto the inputs of more than one virtual joystick simultaneously.
By default, the following keys are mapped onto virtual joystick 0:
- Arrow keys correspond to axes 0 and 1
- The WASD keys correspond to hat 0
- Left ctrl, left alt, z, and x correspond to buttons 0-3
This default mapping can of course be changed at any time.
The mouse
When the mouse input is read, the brick engine will report the X and Y motion of the mouse relative to its last known position. It will also report the current status of up to eight mouse buttons.
Special keys
The special keys that will always be read and returned as a part of the input are:
- Tab
- Space bar
- Enter/return
- Pause
- Escape