Add support for function keys F1-F12

This commit is contained in:
Maxime Coste 2013-11-09 11:12:55 +00:00
parent a7ed017ef3
commit 4b518ee6b9
3 changed files with 46 additions and 0 deletions

View File

@ -80,6 +80,29 @@ KeyList parse_keys(const String& str)
pos = end_pos;
continue;
}
if ((keyname[0] == 'f' or keyname[0] == 'F') and
keyname.length() <= 3)
{
int val = 0;
for (auto i = 1_byte; i < keyname.length(); ++i)
{
char c = keyname[i];
if (c >= '0' and c <= '9')
val = val*10 + c - '0';
else
{
val = -1;
break;
}
}
if (val >= 1 and val <= 12)
{
result.push_back(Key{ modifier, Key::F1 + (val - 1) });
pos = end_pos;
continue;
}
}
}
}
result.push_back({Key::Modifiers::None, Codepoint(str[pos])});
@ -98,6 +121,11 @@ String key_to_str(Key key)
named = true;
res = it->first;
}
else if (key.key >= Key::F1 and key.key < Key::F12)
{
named = true;
res = "F" + to_string((int)(Codepoint)key.key - (int)(Codepoint)Key::F1 + 1);
}
else
res = codepoint_to_str(key.key);

View File

@ -32,6 +32,18 @@ struct Key
Home,
End,
BackTab,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
Invalid,
};

View File

@ -354,6 +354,12 @@ Key NCursesUI::get_key()
case KEY_BTAB: return Key::BackTab;
}
for (int i = 0; i < 12; ++i)
{
if (c == KEY_F(i+1))
return Key::F1 + i;
}
if (c >= 0 and c < 256)
{
ungetch(c);