Keyboard input manager. More...
Public Member Functions | |
const Burger::StaticRTTI * | get_StaticRTTI (void) const noexcept override |
Get the description to the class. | |
Keyboard (GameApp *pAppInstance) noexcept | |
Default constructor. | |
virtual | ~Keyboard () |
Default destructor. | |
GameApp * | GetApp (void) const noexcept |
Return the parent application. | |
uint_t | PeekKeyEvent (KeyEvent_t *pEvent) noexcept |
Check if a keyboard event is pending. | |
uint_t | GetKeyEvent (KeyEvent_t *pEvent) noexcept |
Retrieve a keyboard event. | |
void | ClearKey (eScanCode uScanCode) noexcept |
Clear the key event for the specific scan code. | |
eScanCode | AnyPressed (void) const noexcept |
Check if a key is pressed at this very moment. | |
uint_t | HasBeenPressed (eScanCode uScanCode) const noexcept |
Check if the requested key is currently or previously held down. | |
uint_t | HasBeenPressedClear (eScanCode uScanCode) noexcept |
Check if the requested key is currently or previously held down and clear the event. | |
uint_t | IsPressed (eScanCode uScanCode) const noexcept |
Check if the requested key is currently held down. | |
uint_t | GetKey (void) noexcept |
Return the Unicode value of a pending key press. | |
uint_t | GetKeyLowerCase (void) noexcept |
Return a key in lower case. | |
uint_t | GetKeyUpperCase (void) noexcept |
Return a key in upper case. | |
void | Flush (void) noexcept |
Flush the keyboard buffer. | |
uint_t | Wait (void) noexcept |
Wait for a key press. | |
uint_t | PostKeyDown (eScanCode uScanCode) noexcept |
Post a scan code key down. | |
uint_t | PostKeyUp (eScanCode uScanCode) noexcept |
Post a scan code key up. | |
uint_t | PostKey (eScanCode uScanCode) noexcept |
Post a scan code key down and a key up. | |
uint_t | PostUnicodeDown (uint32_t uUnicode) noexcept |
Post an ASCII/Unicode key down. | |
uint_t | PostUnicodeUp (uint32_t uUnicode) noexcept |
Post an ASCII/Unicode key up. | |
uint_t | PostUnicode (uint32_t uUnicode) noexcept |
Post an ASCII/Unicode key down. | |
uint_t | PostKeyEvent (const KeyEvent_t *pEvent) noexcept |
Post the keyboard event. | |
uint_t | EncodeScanCode (KeyEvent_t *pEvent, eScanCode uScanCode) const noexcept |
Convert a scan code to a KeyEvent_t. | |
uint_t | EncodeUnicode (KeyEvent_t *pEvent, uint32_t uUnicode) const noexcept |
Convert a Unicode character to a KeyEvent_t. | |
uint_t | GetCurrentFlags (void) const noexcept |
Return the flags for a KeyEvent_t based on the currently active modifiers. | |
uint_t | DisableWindowsKey (void) noexcept |
Install keyboard intercept function disabling Windows Key. | |
void | EnableWindowsKey (void) noexcept |
Remove keyboard intercept function disabling Windows Key. | |
HHOOK__ * | GetWindowsPreviousKeyboardHook (void) const noexcept |
Return the Windows default Keyboard Hook function. | |
uint_t | IsDirectInputActive (void) const noexcept |
Is DirectInput active? | |
uint_t | PostWindowsKeyEvent (eEvent uEvent, uint32_t uScanCode) noexcept |
Post a windows scan code key event. | |
uint_t | EncodeWindowsScanCode (KeyEvent_t *pEvent, uint_t uWindowsCode) const noexcept |
Convert a windows a scan code to a KeyEvent_t (Windows only) | |
void | AcquireDirectInput (void) noexcept |
Acquire DirectInput (Windows only) | |
void | UnacquireDirectInput (void) noexcept |
Release DirectInput (Windows only) | |
void | ReadSystemKeyboardDelays (void) noexcept |
Read System keyboard delay constants (Windows only) | |
void | DisableAccessibilityShortcutKeys (void) const noexcept |
Disable the accessibility shortcut keys (Windows only) | |
void | RestoreAccessibilityShortcutKeys (void) noexcept |
Restore the accessibility shortcut keys (Windows only) | |
void | ProcessEvent (NSEvent *pEvent) noexcept |
Process a MacOSX keystroke. | |
Public Member Functions inherited from Burger::Base | |
const char * | get_class_name (void) const noexcept |
Get the name of the class. | |
virtual | ~Base () noexcept=default |
Destructor. | |
Static Public Member Functions | |
static eScanCode | StringToScanCode (const char *pString) noexcept |
Convert a string to a scan code. | |
static void | ScanCodeToString (char *pString, uintptr_t uStringSize, eScanCode uScanCode) noexcept |
Convert a scan code into a string. | |
Static Public Attributes | |
static const Burger::StaticRTTI | g_StaticRTTI |
static const uint_t | kBufferSize = 128 |
Number of keystrokes in keyboard cache. | |
Static Public Attributes inherited from Burger::Base | |
static const Burger::StaticRTTI | g_StaticRTTI |
The global description of the class. | |
Protected Member Functions | |
void | Lock (void) noexcept |
void | Unlock (void) noexcept |
Static Protected Member Functions | |
static uintptr_t | WindowsKeyboardThread (void *pData) |
Windows thread for monitoring keyboard events (Windows only) | |
Protected Attributes | |
GameApp * | m_pAppInstance |
Application instances. | |
IDirectInputDevice8W * | m_pKeyboardDevice |
DirectInput Device reference (Windows only) | |
void * | m_pKeyboardEvent |
Event signal for DirectInput (Windows only) | |
void * | m_pKeyboardTimerEvent |
Keyboard repeat timer event (Windows only) | |
HHOOK__ * | m_pPreviousKeyboardHook |
Previous keyboard low level hook. | |
Thread | m_KeyboardThread |
Asynchronous thread monitoring DirectInput (Windows only) | |
uint_t | m_bDirectInput8Acquired |
TRUE if DirectInput8 is active (Windows only) | |
uint_t | m_bRepeatActive |
TRUE if auto repeat time is active (Windows only) | |
volatile uint32_t | m_bQuit |
TRUE when the thread is shutting down (Windows only) | |
Burger_tagSTICKYKEYS | m_DefaultStickyKeys |
Previous settings for Sticky Keys (Windows only) | |
Burger_tagTOGGLEKEYS | m_DefaultToggleKeys |
Previous settings for Toggle Keys (Windows only) | |
Burger_tagFILTERKEYS | m_DefaultFilterKeys |
Previous settings for Filter Keys (Windows only) | |
Mutex | m_KeyboardLock |
Lock for multi-threading (MacOSX and Windows only) | |
uint8_t | m_KeyArray [SC_MAXENTRY+1] |
Array with the current state of the keyboard. | |
uint_t | m_uArrayStart |
Read index for m_KeyEvents. | |
uint_t | m_uArrayEnd |
Write index for m_KeyEvents. | |
uint_t | m_uInitialDelay |
Initial delay in ms for autorepeat. | |
uint_t | m_uRepeatDelay |
Delay between repeating keystrokes. | |
KeyEvent_t | m_KeyEvents [kBufferSize] |
Circular buffer holding keyboard events. | |
KeyEvent_t | m_RepeatEvent |
Event to post on a repeat. | |
Private Member Functions | |
Keyboard (const Keyboard &)=delete | |
Keyboard & | operator= (const Keyboard &)=delete |
Keyboard (Keyboard &&)=delete | |
Keyboard & | operator= (Keyboard &&)=delete |
Keyboard input manager.
This class manages keyboard input down to the individual key cap. It's main use is to use the keyboard as a gaming input device. Emphasis is on speed, low latency and accuracy.
When this class is instantiated, a keyboard monitor is activated which will check for all key strokes. There are a maximum of 256 keyboard scan codes that can be monitored. Each byte will contain the current status of the key by scan code. The lowest bit (mask with 0x01) will determine the key down status at the current moment in time. Bit #1 (mask with 0x02) is set when the key is pressed but never cleared unless you call a function that clears the flag or Keyboard::Flush() with flushes all events.
This array is checked by several routines that use the keyboard as a game input device.
The array is volatile since some keyboard monitors run as a separate thread.
anonymous enum |
Unicode translations for several common keys.
When these keys are pressed, they return these specific Unicode compatible "ASCII" codes.
Keycode modifier flags.
When a keyboard event is generated, a set of flags can be attached to denote any type of modification that was applied to the keystroke at the moment of press.
Unified scan codes.
All platforms will have their keyboard scan codes mapped to these enumerations. It allows an application to save a keyboard mapping file on one platform and read it in on another and have the keys map properly.
|
privatedelete |
|
privatedelete |
|
noexcept |
Default constructor.
Installs the heartbeat thread to periodically refresh the m_KeyArray and generate the lists of upcoming key events
|
virtual |
Default destructor.
Shuts down the heartbeat thread and releases all allocated system resources.
|
noexcept |
Acquire DirectInput (Windows only)
Call Acquire() on the DirectInput mouse device.
|
noexcept |
Check if a key is pressed at this very moment.
Scan the keyboard status array and return the scan code of the first key found that's held down.
|
noexcept |
Clear the key event for the specific scan code.
If the code is invalid, do nothing. Otherwise, clear the keyboard flags in the m_KeyArray
uScanCode | Valid keyboard scan code to check |
|
noexcept |
Disable the accessibility shortcut keys (Windows only)
There are some keyboard modes that are intended for people with typing problems. If any of these features were not enabled when the application started, disable the ability to turn them on by using keyboard shortcuts. It helps prevent a player using the keyboard from accidentally enabling this feature while mashing buttons like crazy.
|
noexcept |
Install keyboard intercept function disabling Windows Key.
Installs a keyboard hook that disables the windows key.
|
noexcept |
Remove keyboard intercept function disabling Windows Key.
If DisableWindowsKey(void) was called, it installed a keyboard hook that disabled the windows key. This function removes that intercept.
|
noexcept |
Convert a scan code to a KeyEvent_t.
Given a scan code, check the state of the keyboard and determine the Unicode/ASCII code to be generated for this keypress.
|
noexcept |
Convert a Unicode character to a KeyEvent_t.
Given a Unicode character, look up the scan code, if available, and fill in a KeyEvent_t to be generated for this keypress.
|
noexcept |
Convert a windows a scan code to a KeyEvent_t (Windows only)
Convert a windows scan code to a Keyboard event
|
noexcept |
Flush the keyboard buffer.
Release all pending keyboard events and erase the keyboard array.
|
overridevirtualnoexcept |
Get the description to the class.
This virtual function will pull the pointer to the StaticRTTI instance that has the name of the class. Due to it being virtual, it will be the name of the most derived class.
Reimplemented from Burger::Base.
|
inlinenoexcept |
|
noexcept |
Return the flags for a KeyEvent_t based on the currently active modifiers.
Check the state of previously pressed keys and return the modifier flags for converting a scan code into an ASCII/Unicode value.
|
noexcept |
Return the Unicode value of a pending key press.
Check if a key is pending and return zero if not, else return the Unicode value. All key up events up until the key down are consumed.
|
noexcept |
Retrieve a keyboard event.
If a keyboard event is in the queue, return the event and remove it from the list.
pEvent | Pointer to a KeyEvent_t structure to receive the event. |
|
noexcept |
Return a key in lower case.
Check if a key is pending and return zero if not, else the Unicode code in lower case
|
noexcept |
Return a key in upper case.
Check if a key is pending and return zero if not, else the Unicode code in upper case
|
inlinenoexcept |
Return the Windows default Keyboard Hook function.
If a keyboard hook was installed via a call to DisableWindowsKey(), this pointer is valid and points to the function in Windows to be passed to the function CallNextHookEx()
|
noexcept |
Check if the requested key is currently or previously held down.
If a key has been pressed, return TRUE. If the key has not been pressed or the scan code is invalid, return FALSE. This function will not clear the event. Use HasBeenPressedClear() to clear the event
uScanCode | Valid Scan code |
|
noexcept |
|
inlinenoexcept |
|
noexcept |
|
inlineprotectednoexcept |
|
noexcept |
Check if a keyboard event is pending.
See if a key is pending from the keyboard, if so, return the event without removing it from the queue.
pEvent | Pointer to a KeyEvent_t structure to receive the event. |
|
noexcept |
Post a scan code key down and a key up.
Given a keyboard scan code, post a key down event followed by a key up event
uScanCode | Keyboard scan code |
|
noexcept |
Post a scan code key down.
Given a keyboard scan code, post a key down event
uScanCode | Keyboard scan code |
|
noexcept |
Post the keyboard event.
Given a valid keyboard event structure, post the event
pEvent | Pointer to a valid keyboard event |
|
noexcept |
Post a scan code key up.
Given a keyboard scan code, post a key up event
uScanCode | Keyboard scan code |
|
noexcept |
Post an ASCII/Unicode key down.
Given an ASCII/Unicode character, post a key down event
uUnicode | Unicode32 character |
|
noexcept |
Post an ASCII/Unicode key down.
Given an ASCII/Unicode character, post a key down event
uUnicode | Unicode32 character |
|
noexcept |
Post an ASCII/Unicode key up.
Given an ASCII/Unicode character, post a key up event
uUnicode | Unicode32 character |
|
noexcept |
Post a windows scan code key event.
Given a Windows keyboard scan code, convert it to a Burgerlib key press and post the event
uEvent | Type of key event to post |
uScanCode | Windows keyboard scan code |
|
noexcept |
Process a MacOSX keystroke.
When an NSEvent is created that is of a type of NSKeyDown, NSKeyUp or NSFlagsChanged, this function will process the event into a Burgerlib compatible keystroke
pEvent | Pointer to a NSEvent with a keyboard event. |
|
noexcept |
Read System keyboard delay constants (Windows only)
On startup and when a WM_SETTINGCHANGE event is triggered, read the settings for the keyboard auto-repeat from Windows and record it so auto-repeat is as the user requested it.
|
noexcept |
Restore the accessibility shortcut keys (Windows only)
Restore the accessibility shortcut keys to the settings that were captured upon instantiation of the Keyboard class
|
staticnoexcept |
Convert a scan code into a string.
Given a Burgerlib keyboard scan code, return a string that best describes the scan code. If StringSize is 0, nothing will be done since the output buffer is invalid.
pString | Pointer to a "C" string buffer to store the result |
uStringSize | sizeof() the buffer to prevent overruns |
uScanCode | Valid Burgerlib scan code |
|
staticnoexcept |
Convert a string to a scan code.
Given a pointer to a string describing a keyboard scan code. Look up the scan code and return the value. I return a -1 if there is no match.
pString | Pointer to a "C" string |
|
noexcept |
Release DirectInput (Windows only)
Call Unacquire() on the DirectInput mouse device.
|
inlineprotectednoexcept |
|
noexcept |
Wait for a key press.
Wait for a keypress, but call GetKey() to allow screen savers to kick in.
|
staticprotected |
Windows thread for monitoring keyboard events (Windows only)
Burgerlib reads keyboard events using DirectInput and asynchronous thread events.
This function runs as a separate thread and processes all DirectInput events.
pData | Pointer to the Keyboard class instance |
|
static |
|
static |
Number of keystrokes in keyboard cache.
|
protected |
TRUE if DirectInput8 is active (Windows only)
|
protected |
TRUE when the thread is shutting down (Windows only)
|
protected |
TRUE if auto repeat time is active (Windows only)
|
protected |
Previous settings for Filter Keys (Windows only)
|
protected |
Previous settings for Sticky Keys (Windows only)
|
protected |
Previous settings for Toggle Keys (Windows only)
|
protected |
Array with the current state of the keyboard.
|
protected |
Asynchronous thread monitoring DirectInput (Windows only)
|
protected |
Circular buffer holding keyboard events.
|
protected |
Application instances.
|
protected |
DirectInput Device reference (Windows only)
|
protected |
Event signal for DirectInput (Windows only)
|
protected |
Keyboard repeat timer event (Windows only)
|
protected |
Previous keyboard low level hook.
|
protected |
Event to post on a repeat.
|
protected |
Write index for m_KeyEvents.
|
protected |
Read index for m_KeyEvents.
|
protected |
Initial delay in ms for autorepeat.
|
protected |
Delay between repeating keystrokes.