Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
keycode.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "exceptions.h"
8#include "irrlichttypes.h"
9#include <Keycodes.h>
10#include <IEventReceiver.h>
11#include <string>
12
14{
15public:
16 UnknownKeycode(const char *s) :
17 BaseException(s) {};
18};
19
20/* A key press, consisting of either an Irrlicht keycode
21 or an actual char */
22
24{
25public:
26 KeyPress() = default;
27
28 KeyPress(const char *name);
29
30 KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character = false);
31
32 bool operator==(const KeyPress &o) const
33 {
34 return (Char > 0 && Char == o.Char) || (valid_kcode(Key) && Key == o.Key);
35 }
36
37 const char *sym() const;
38 const char *name() const;
39
40protected:
41 static bool valid_kcode(irr::EKEY_CODE k)
42 {
43 return k > 0 && k < irr::KEY_KEY_CODES_COUNT;
44 }
45
46 irr::EKEY_CODE Key = irr::KEY_KEY_CODES_COUNT;
47 wchar_t Char = L'\0';
48 std::string m_name = "";
49};
50
51// Global defines for convenience
52
53extern const KeyPress EscapeKey;
54
55extern const KeyPress LMBKey;
56extern const KeyPress MMBKey; // Middle Mouse Button
57extern const KeyPress RMBKey;
58
59// Key configuration getter
60const KeyPress &getKeySetting(const char *settingname);
61
62// Clear fast lookup cache
63void clearKeyCache();
64
65irr::EKEY_CODE keyname_to_keycode(const char *name);
Definition exceptions.h:12
Definition keycode.h:24
wchar_t Char
Definition keycode.h:47
const char * name() const
Definition keycode.cpp:323
irr::EKEY_CODE Key
Definition keycode.h:46
bool operator==(const KeyPress &o) const
Definition keycode.h:32
static bool valid_kcode(irr::EKEY_CODE k)
Definition keycode.h:41
const char * sym() const
Definition keycode.cpp:318
std::string m_name
Definition keycode.h:48
KeyPress()=default
Definition keycode.h:14
UnknownKeycode(const char *s)
Definition keycode.h:16
const KeyPress EscapeKey
irr::EKEY_CODE keyname_to_keycode(const char *name)
Definition keycode.cpp:364
const KeyPress RMBKey
const KeyPress & getKeySetting(const char *settingname)
Definition keycode.cpp:348
const KeyPress LMBKey
const KeyPress MMBKey
void clearKeyCache()
Definition keycode.cpp:359