![]() |
The LARC Game Engine
A Simple Game Engine from the Laboratory for Recreational Computing
|
The keyboard handler. More...
#include <Keyboard.h>
Public Member Functions | |
LKeyboard () | |
Constructor. More... | |
void | GetState () |
Poll the keyboard state. More... | |
const bool | Down (const WPARAM) const |
Check for key down. More... | |
bool | TriggerDown (const WPARAM) |
Check for key changing from up to down. More... | |
bool | TriggerUp (const WPARAM) |
Check for key changing from down to up. More... | |
bool | TriggerDown () |
Check for any key changing from up to down. More... | |
bool | TriggerUp () |
Check for any key changing from down to up. More... | |
Private Member Functions | |
bool | Trigger (const WPARAM, bool) |
Check for key changing state. More... | |
bool | Trigger (bool) |
Check for any key changing state. More... | |
Private Attributes | |
unsigned char | m_pState [NUMKEYS] |
Space for current state of keys. | |
unsigned char | m_pOldState [NUMKEYS] |
Space for current state of keys. | |
Static Private Attributes | |
static const int | NUMKEYS = 256 |
Number of keys on the keyboard. | |
Additional Inherited Members | |
![]() | |
static HWND | m_Hwnd = 0 |
Window handle. | |
static HINSTANCE | m_hInst = 0 |
Instance handle. | |
static bool | m_bExitSizeMove |
User just finished moving/resizing window. | |
This is a polled keyboard handler. Its GetState() function must be called once per frame. The keyboard state from the previous frame is retained so that queries can determine whether a key changed state.
LKeyboard::LKeyboard | ( | ) |
The constructor initializes all key states to zero.
const bool LKeyboard::Down | ( | const WPARAM | k | ) | const |
Check whether a key is currently down. This function assumes that GetState() has been called recently to get the current keyboard state.
k | Virtual key code of key to check. |
void LKeyboard::GetState | ( | ) |
Use the Windows API GetKeyboardState function to get the state of all 256 keys on the keyboard. The results are stored as an array of bytes in m_pState, while the previous state is also stored in m_pOldState.
|
private |
Check whether any key changed state in a particular direction, not including the ESC key or the function keys F1 through F12. This function assumes that GetState() has been called recently to get the current keyboard state.
bDown | True if we're checking for key down, false if up. |
|
private |
Check whether a key has just changed state, ie. whether it just went up or just went down. This function assumes that GetState() has been called recently to get the current keyboard state.
k | Virtual key code of key to check. |
bDown | True if we are checking for key down, false for key up. |
bool LKeyboard::TriggerDown | ( | ) |
Check whether any key went down, not including the ESC key or the function keys F1 through F12. This includes the mouse buttons. This function assumes that GetState() has been called recently to get the current keyboard state.
bool LKeyboard::TriggerDown | ( | const WPARAM | k | ) |
Check whether a key went down. This function assumes that GetState() has been called recently to get the current keyboard state.
k | Virtual key code of key to check. |
bool LKeyboard::TriggerUp | ( | ) |
Check whether any key went up, not including the ESC key or the function keys F1 through F12. This includes the mouse buttons. This function assumes that GetState() has been called recently to get the current keyboard state.
bool LKeyboard::TriggerUp | ( | const WPARAM | k | ) |
Check whether a key went up. This function assumes that GetState() has been called recently to get the current keyboard state.
k | Virtual key code of key to check. |