SAGE
A Simple Academic Game Engine
Loading...
Searching...
No Matches
Sage::CKeyboard Class Reference

The keyboard handler. More...

#include <SageKeyboard.h>

Inheritance diagram for Sage::CKeyboard:
Collaboration diagram for Sage::CKeyboard:

Public Member Functions

 CKeyboard ()
 Constructor.
 
void GetState ()
 Poll the keyboard state.
 
const bool Down (const WPARAM) const
 Check for key down.
 
bool TriggerDown (const WPARAM)
 Check for key going down.
 
bool TriggerUp (const WPARAM)
 Check for key going up.
 
bool TriggerDown ()
 Check for any key going down.
 
bool TriggerUp ()
 Check for any key going up.
 

Private Member Functions

bool Trigger (const WPARAM, bool)
 Check for key changing state.
 
bool Trigger (bool)
 Check for any key changing state.
 

Private Attributes

BYTE m_pState [NUMKEYS] = {0}
 Space for current state of keys.
 
BYTE m_pOldState [NUMKEYS] = {0}
 Space for current state of keys.
 

Static Private Attributes

static const UINT NUMKEYS = 256
 Number of keys on the keyboard.
 

Additional Inherited Members

- Static Protected Attributes inherited from Sage::CWindowDesc
static HWND m_Hwnd = 0
 Window handle.
 
static HINSTANCE m_hInst = 0
 Instance handle.
 
static bool m_bExitSizeMove = true
 User just finished moving/resizing window.
 
- Static Protected Attributes inherited from Sage::CScreenshotFlag
static bool m_bScreenShot = false
 Screenshot flag.
 

Detailed Description

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. Mouse button clicks are also handled here using virtual key codes VK_LBUTTON, VK_MBUTTON, VK_RBUTTON, VK_XBUTTON1, and VK_XBUTTON2.

Constructor & Destructor Documentation

◆ CKeyboard()

CKeyboard::CKeyboard ( )

The constructor initializes all key states to zero.

Member Function Documentation

◆ Down()

const bool CKeyboard::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.

Parameters
kVirtual key code of key to check.
Returns
True if key k is down.

◆ GetState()

void CKeyboard::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. If the P key is triggered down, then a screenshot save is triggered by setting g_bScreenShot to true. The actual save gets done in CRenderer3D::EndFrame. If VK_ESCAPE is triggered down, then game exit is indicated by posting a WM_DESTROY message to the window handle.

Here is the call graph for this function:

◆ Trigger() [1/2]

bool CKeyboard::Trigger ( bool bDown)
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.

Parameters
bDownTrue if we're checking for key down, false if up.
Returns
True if a key changed state.
Here is the call graph for this function:

◆ Trigger() [2/2]

bool CKeyboard::Trigger ( const WPARAM k,
bool bDown )
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.

Parameters
kVirtual key code of key to check.
bDownTrue if we are checking for key down, false for key up.
Returns
True if key k was changed to the desired state.
Here is the caller graph for this function:

◆ TriggerDown() [1/2]

bool CKeyboard::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.

Returns
True if a key went down.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TriggerDown() [2/2]

bool CKeyboard::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.

Parameters
kVirtual key code of key to check.
Returns
True if key k went down.
Here is the call graph for this function:

◆ TriggerUp() [1/2]

bool CKeyboard::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.

Returns
True if a key went up.
Here is the call graph for this function:

◆ TriggerUp() [2/2]

bool CKeyboard::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.

Parameters
kVirtual key code of key to check.
Returns
True if key k went up.
Here is the call graph for this function: