Luanti 5.17.0-dev
Loading...
Searching...
No Matches
KeyPress Class Reference

#include <keycode.h>

Public Types

enum class  InputType {
  KEYBOARD , MOUSE_BUTTON , GAME_ACTION , GAMEPAD_BUTTON ,
  GAMEPAD_AXIS_PLUS , GAMEPAD_AXIS_MINUS
}
 The type of the input value. More...
enum class  InputSourceType {
  INVALID , KEYBOARD , MOUSE , TOUCHSCREEN ,
  GAMEPAD
}
 Type of the input device. More...

Public Member Functions

 KeyPress ()=default
 KeyPress (const std::string &name)
 KeyPress (const SEvent::SKeyInput &in)
 KeyPress (const SEvent::SMouseInput &in)
 KeyPress (const SEvent::SGamepadButtonEvent &in)
 KeyPress (const SEvent::SGamepadAxisEvent &in)
 KeyPress (GameKeyType key)
std::string sym () const
std::string name () const
u32 getScancode () const
bool operator== (KeyPress o) const
bool operator!= (KeyPress o) const
bool operator< (KeyPress o) const
InputType getType () const
InputSourceType getSourceType () const
 Get the source type of input.
KeyPress getOppositeAxisDirection () const
 Get the joystick axis in the opposite direction (if available).
 operator bool () const

Static Public Member Functions

static KeyPress getSpecialKey (const std::string &name)

Private Types

using value_type = std::variant<u32, u32, GameKeyType, GamepadButton, GamepadAxis, GamepadAxis>
template<InputType I>
using value_alternative_t = std::variant_alternative_t<static_cast<size_t>(I), value_type>

Private Member Functions

template<InputType I>
bool loadUnsignedFromPrefix (const std::string &name, const std::string &prefix)
bool loadFromScancode (const std::string &name)
void loadFromKey (EKEY_CODE keycode, wchar_t keychar)
template<InputType I>
value_alternative_t< I > get () const
template<InputType I, typename T>
getCast () const
template<InputType I>
std::add_pointer_t< const value_alternative_t< I > > getIf () const
template<InputType I>
void emplace (value_alternative_t< I > newValue)

Private Attributes

value_type value

Member Typedef Documentation

◆ value_alternative_t

template<InputType I>
using KeyPress::value_alternative_t = std::variant_alternative_t<static_cast<size_t>(I), value_type>
private

◆ value_type

using KeyPress::value_type = std::variant<u32, u32, GameKeyType, GamepadButton, GamepadAxis, GamepadAxis>
private

Member Enumeration Documentation

◆ InputSourceType

enum class KeyPress::InputSourceType
strong

Type of the input device.

Enumerator
INVALID 
KEYBOARD 
MOUSE 
TOUCHSCREEN 
GAMEPAD 

◆ InputType

enum class KeyPress::InputType
strong

The type of the input value.

When constructing the KeyPress object from an Irrilcht event, the direction of the gamepad axis is determined by the value along the axis. 0 is mapped to the positive direction.

Enumerator
KEYBOARD 

Keyboard input (scancodes).

MOUSE_BUTTON 

Mouse button input.

GAME_ACTION 

GameKeyType input passed by touchscreen buttons.

GAMEPAD_BUTTON 

Gamepad button.

GAMEPAD_AXIS_PLUS 

Gamepad axis in the positive direction.

GAMEPAD_AXIS_MINUS 

Gamepad axis in the negative direction.

Constructor & Destructor Documentation

◆ KeyPress() [1/7]

KeyPress::KeyPress ( )
default

References name().

Referenced by getOppositeAxisDirection(), getSpecialKey(), operator!=(), operator<(), and operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ KeyPress() [2/7]

KeyPress::KeyPress ( const std::string & name)

References loadFromKey(), loadUnsignedFromPrefix(), lookup_keyname(), and name().

Here is the call graph for this function:

◆ KeyPress() [3/7]

KeyPress::KeyPress ( const SEvent::SKeyInput & in)

References emplace(), and loadFromKey().

Here is the call graph for this function:

◆ KeyPress() [4/7]

KeyPress::KeyPress ( const SEvent::SMouseInput & in)

References emplace().

Here is the call graph for this function:

◆ KeyPress() [5/7]

KeyPress::KeyPress ( const SEvent::SGamepadButtonEvent & in)

References emplace().

Here is the call graph for this function:

◆ KeyPress() [6/7]

KeyPress::KeyPress ( const SEvent::SGamepadAxisEvent & in)

References emplace().

Here is the call graph for this function:

◆ KeyPress() [7/7]

KeyPress::KeyPress ( GameKeyType key)
inline

References value.

Member Function Documentation

◆ emplace()

template<InputType I>
void KeyPress::emplace ( value_alternative_t< I > newValue)
inlineprivate

References value.

Referenced by KeyPress(), KeyPress(), KeyPress(), KeyPress(), getOppositeAxisDirection(), loadFromKey(), and loadUnsignedFromPrefix().

Here is the caller graph for this function:

◆ get()

template<InputType I>
value_alternative_t< I > KeyPress::get ( ) const
inlineprivate

References value.

Referenced by getCast(), getOppositeAxisDirection(), name(), operator bool(), and sym().

Here is the caller graph for this function:

◆ getCast()

template<InputType I, typename T>
T KeyPress::getCast ( ) const
inlineprivate

References get().

Referenced by sym().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIf()

template<InputType I>
std::add_pointer_t< const value_alternative_t< I > > KeyPress::getIf ( ) const
inlineprivate

References value.

Referenced by getScancode().

Here is the caller graph for this function:

◆ getOppositeAxisDirection()

KeyPress KeyPress::getOppositeAxisDirection ( ) const

Get the joystick axis in the opposite direction (if available).

References KeyPress(), emplace(), GAMEPAD_AXIS_MINUS, GAMEPAD_AXIS_PLUS, get(), and getType().

Here is the call graph for this function:

◆ getScancode()

u32 KeyPress::getScancode ( ) const
inline

References getIf().

Referenced by name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSourceType()

KeyPress::InputSourceType KeyPress::getSourceType ( ) const

Get the source type of input.

References GAME_ACTION, GAMEPAD, GAMEPAD_AXIS_MINUS, GAMEPAD_AXIS_PLUS, GAMEPAD_BUTTON, getType(), INVALID, KEYBOARD, MOUSE, MOUSE_BUTTON, and TOUCHSCREEN.

Here is the call graph for this function:

◆ getSpecialKey()

KeyPress KeyPress::getSpecialKey ( const std::string & name)
static

References KeyPress(), name(), and specialKeyCache.

Here is the call graph for this function:

◆ getType()

InputType KeyPress::getType ( ) const
inline

References value.

Referenced by getOppositeAxisDirection(), getSourceType(), name(), operator bool(), and sym().

Here is the caller graph for this function:

◆ loadFromKey()

void KeyPress::loadFromKey ( EKEY_CODE keycode,
wchar_t keychar )
private

References emplace(), and RenderingEngine::get_raw_device().

Referenced by KeyPress(), and KeyPress().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFromScancode()

bool KeyPress::loadFromScancode ( const std::string & name)
private

References name().

Here is the call graph for this function:

◆ loadUnsignedFromPrefix()

template<KeyPress::InputType I>
bool KeyPress::loadUnsignedFromPrefix ( const std::string & name,
const std::string & prefix )
private

References emplace(), name(), p(), and str_starts_with().

Referenced by KeyPress().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

std::string KeyPress::name ( ) const

References fmtgettext(), GAMEPAD_AXIS_MINUS, GAMEPAD_AXIS_PLUS, GAMEPAD_BUTTON, get(), RenderingEngine::get_raw_device(), getScancode(), getType(), KEYBOARD, table_key::LangName, lookup_scancode(), MOUSE_BUTTON, name(), and strgettext().

Referenced by KeyPress(), KeyPress(), getSpecialKey(), ModApiMenuCommon::l_get_key_description(), loadFromScancode(), loadUnsignedFromPrefix(), name(), and GUIButtonKey::setKey().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator bool()

KeyPress::operator bool ( ) const

References GAME_ACTION, GAMEPAD_AXIS_MINUS, GAMEPAD_AXIS_PLUS, GAMEPAD_BUTTON, get(), getType(), KeyType::INTERNAL_ENUM_COUNT, KEYBOARD, and MOUSE_BUTTON.

Here is the call graph for this function:

◆ operator!=()

bool KeyPress::operator!= ( KeyPress o) const
inline

References KeyPress().

Here is the call graph for this function:

◆ operator<()

bool KeyPress::operator< ( KeyPress o) const
inline

References KeyPress(), and value.

Here is the call graph for this function:

◆ operator==()

bool KeyPress::operator== ( KeyPress o) const
inline

References KeyPress(), and value.

Here is the call graph for this function:

◆ sym()

std::string KeyPress::sym ( ) const

References GAMEPAD_AXIS_MINUS, GAMEPAD_AXIS_PLUS, GAMEPAD_BUTTON, get(), getCast(), getType(), KEYBOARD, and MOUSE_BUTTON.

Referenced by GUIButtonKey::setKey().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ value

value_type KeyPress::value
private

The documentation for this class was generated from the following files: