add scancode-syntax for keybinding settings
This commit is contained in:
parent
cd8dee2779
commit
0aef1c4a5c
@ -242,7 +242,8 @@ KeyCode CIrrDeviceSDL::getKeyFromScancode(const u32 scancode) const
|
||||
auto keycode = SDL_GetKeyFromScancode((SDL_Scancode)scancode);
|
||||
const auto &keyentry = KeyMap.find(keycode);
|
||||
auto irrcode = keyentry != KeyMap.end() ? keyentry->second : KEY_UNKNOWN;
|
||||
return KeyCode(irrcode, keycode);
|
||||
auto keychar = findCharToPassToIrrlicht(keycode, irrcode, false);
|
||||
return KeyCode(irrcode, keychar);
|
||||
}
|
||||
|
||||
void CIrrDeviceSDL::resetReceiveTextInputEvents()
|
||||
|
@ -284,6 +284,8 @@ static const table_key &lookup_scancode(const u32 scancode)
|
||||
|
||||
KeyPress::KeyPress(const std::string_view &name)
|
||||
{
|
||||
if (loadFromScancode(name))
|
||||
return;
|
||||
const auto &key = lookup_keyname(name);
|
||||
KeyCode keycode(key.Key, key.Char);
|
||||
scancode = RenderingEngine::get_raw_device()->getScancodeFromKey(keycode);
|
||||
@ -291,12 +293,27 @@ KeyPress::KeyPress(const std::string_view &name)
|
||||
|
||||
std::string KeyPress::sym() const
|
||||
{
|
||||
return lookup_scancode(scancode).Name;
|
||||
const auto &name = lookup_scancode(scancode).Name;
|
||||
if (!name.empty() || scancode == 0)
|
||||
return name;
|
||||
return formatScancode();
|
||||
}
|
||||
|
||||
std::string KeyPress::name() const
|
||||
{
|
||||
return lookup_scancode(scancode).LangName;
|
||||
const auto &name = lookup_scancode(scancode).LangName;
|
||||
auto table_key = lookup_scancode(scancode);
|
||||
if (!name.empty() || scancode == 0)
|
||||
return name;
|
||||
return formatScancode();
|
||||
}
|
||||
|
||||
bool KeyPress::loadFromScancode(const std::string_view &name)
|
||||
{
|
||||
if (name.size() < 2 || name[0] != '<')
|
||||
return false;
|
||||
scancode = strtoul(name.data()+1, NULL, 10);
|
||||
return scancode != 0;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, KeyPress> KeyPress::specialKeyCache;
|
||||
|
@ -35,6 +35,13 @@ public:
|
||||
static const KeyPress &getSpecialKey(const std::string &name);
|
||||
|
||||
private:
|
||||
bool loadFromScancode(const std::string_view &name);
|
||||
|
||||
inline std::string formatScancode() const
|
||||
{
|
||||
return "<" + std::to_string(scancode) + ">";
|
||||
}
|
||||
|
||||
u32 scancode = 0;
|
||||
|
||||
static std::unordered_map<std::string, KeyPress> specialKeyCache;
|
||||
|
Loading…
Reference in New Issue
Block a user