keycode.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "exceptions.h"
  18. #include "irrlichttypes.h"
  19. #include "Keycodes.h"
  20. #include <IEventReceiver.h>
  21. #include <string>
  22. class UnknownKeycode : public BaseException
  23. {
  24. public:
  25. UnknownKeycode(const char *s) :
  26. BaseException(s) {};
  27. };
  28. /* A key press, consisting of either an Irrlicht keycode
  29. or an actual char */
  30. class KeyPress
  31. {
  32. public:
  33. KeyPress() = default;
  34. KeyPress(const char *name);
  35. KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character = false);
  36. bool operator==(const KeyPress &o) const
  37. {
  38. return (Char > 0 && Char == o.Char) || (valid_kcode(Key) && Key == o.Key);
  39. }
  40. const char *sym() const;
  41. const char *name() const;
  42. protected:
  43. static bool valid_kcode(irr::EKEY_CODE k)
  44. {
  45. return k > 0 && k < irr::KEY_KEY_CODES_COUNT;
  46. }
  47. irr::EKEY_CODE Key = irr::KEY_KEY_CODES_COUNT;
  48. wchar_t Char = L'\0';
  49. std::string m_name = "";
  50. };
  51. extern const KeyPress EscapeKey;
  52. extern const KeyPress CancelKey;
  53. // Key configuration getter
  54. KeyPress getKeySetting(const char *settingname);
  55. // Clear fast lookup cache
  56. void clearKeyCache();
  57. irr::EKEY_CODE keyname_to_keycode(const char *name);