ScummVM API documentation
Common::KeyState Struct Reference

#include <keyboard.h>

Inheritance diagram for Common::KeyState:
MM::MM1::KeypressMessage

Public Member Functions

 KeyState (KeyCode kc=KEYCODE_INVALID)
 
 KeyState (KeyCode kc, uint16 asc, byte f=0)
 
void reset ()
 
bool hasFlags (byte f) const
 
bool operator== (const KeyState &x) const
 

Public Attributes

KeyCode keycode
 
uint16 ascii
 
byte flags
 

Detailed Description

Keyboard status, as used in the Event struct.

Member Function Documentation

◆ hasFlags()

bool Common::KeyState::hasFlags ( byte  f) const
inline

Check whether the non-sticky flags are exactly as specified by f. This ignores the sticky flags (KBD_NUM, KBD_CAPS, KBD_SCRL). Sticky flags should never be passed to this function. If you just want to check whether a modifier flag is set, just bit-and the flag. E.g. to check whether the control key modifier is set, you can write if (keystate.flags & KBD_CTRL) { ... }

◆ operator==()

bool Common::KeyState::operator== ( const KeyState x) const
inline

Check if two key states are equal. This implementation ignores the state of the sticky flags (caps lock, num lock, scroll lock) completely.

Member Data Documentation

◆ keycode

KeyCode Common::KeyState::keycode

Abstract key code (will be the same for any given key regardless of modifiers being held at the same time.

◆ ascii

uint16 Common::KeyState::ascii

ASCII-value of the pressed key (if any). This depends on modifiers, i.e. pressing the 'A' key results in different values here depending on the status of shift, alt and caps lock. This should be used rather than keycode for text input to avoid keyboard layout issues. For example you cannot assume that KEYCODE_0 without a modifier will be '0' (on AZERTY keyboards it is not).

◆ flags

byte Common::KeyState::flags

Status of the modifier keys. Bits are set in this for each pressed modifier. We distinguish 'non-sticky' and 'sticky' modifiers flags. The former are only set while certain keys (ctrl, alt, shift) are pressed by the user; the latter (num lock, caps lock, scroll lock) are activated when certain keys are pressed and released; and deactivated when that key is pressed and released a second time.

See also
KBD_CTRL, KBD_ALT, KBD_SHIFT, KBD_NUM, KBD_CAPS, KBD_SCRL

The documentation for this struct was generated from the following file: