2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-05-14 15:43:26 +03:00
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2011-05-15 13:06:46 +03:00
|
|
|
|
2024-02-22 16:44:49 +01:00
|
|
|
#include "exceptions.h"
|
2012-06-17 04:00:31 +03:00
|
|
|
#include "irrlichttypes.h"
|
2024-04-20 18:52:52 +02:00
|
|
|
#include <Keycodes.h>
|
2012-06-17 04:00:31 +03:00
|
|
|
#include <IEventReceiver.h>
|
2011-06-01 19:44:07 +02:00
|
|
|
#include <string>
|
2011-05-14 15:43:26 +03:00
|
|
|
|
2024-02-22 16:44:49 +01:00
|
|
|
class UnknownKeycode : public BaseException
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UnknownKeycode(const char *s) :
|
|
|
|
BaseException(s) {};
|
|
|
|
};
|
|
|
|
|
2011-08-13 22:44:31 +02:00
|
|
|
/* A key press, consisting of either an Irrlicht keycode
|
|
|
|
or an actual char */
|
|
|
|
|
|
|
|
class KeyPress
|
|
|
|
{
|
|
|
|
public:
|
2017-08-18 08:21:01 +02:00
|
|
|
KeyPress() = default;
|
|
|
|
|
2011-08-13 22:44:31 +02:00
|
|
|
KeyPress(const char *name);
|
|
|
|
|
2017-04-23 09:52:40 +02:00
|
|
|
KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character = false);
|
2011-08-13 22:44:31 +02:00
|
|
|
|
|
|
|
bool operator==(const KeyPress &o) const
|
|
|
|
{
|
2023-10-29 00:25:38 +02:00
|
|
|
return (Char > 0 && Char == o.Char) || (valid_kcode(Key) && Key == o.Key);
|
2011-08-13 22:44:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *sym() const;
|
|
|
|
const char *name() const;
|
2017-04-23 09:52:40 +02:00
|
|
|
|
2011-08-13 22:44:31 +02:00
|
|
|
protected:
|
|
|
|
static bool valid_kcode(irr::EKEY_CODE k)
|
|
|
|
{
|
|
|
|
return k > 0 && k < irr::KEY_KEY_CODES_COUNT;
|
|
|
|
}
|
|
|
|
|
2017-06-17 19:11:28 +02:00
|
|
|
irr::EKEY_CODE Key = irr::KEY_KEY_CODES_COUNT;
|
|
|
|
wchar_t Char = L'\0';
|
|
|
|
std::string m_name = "";
|
2011-08-13 22:44:31 +02:00
|
|
|
};
|
|
|
|
|
2024-04-20 18:52:52 +02:00
|
|
|
// Global defines for convenience
|
|
|
|
|
2011-08-13 22:44:31 +02:00
|
|
|
extern const KeyPress EscapeKey;
|
2011-05-14 15:43:26 +03:00
|
|
|
|
2024-04-20 18:52:52 +02:00
|
|
|
extern const KeyPress LMBKey;
|
|
|
|
extern const KeyPress MMBKey; // Middle Mouse Button
|
|
|
|
extern const KeyPress RMBKey;
|
|
|
|
|
2011-05-14 15:43:26 +03:00
|
|
|
// Key configuration getter
|
2024-04-20 18:52:52 +02:00
|
|
|
const KeyPress &getKeySetting(const char *settingname);
|
2011-07-22 21:53:50 +02:00
|
|
|
|
|
|
|
// Clear fast lookup cache
|
|
|
|
void clearKeyCache();
|
2011-05-14 15:43:26 +03:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
irr::EKEY_CODE keyname_to_keycode(const char *name);
|