I would like to convert a string representing a key on the keyboard to a keycode enum like Qt::Key (or anything else). Example conversions would be:
"Ctrl"
toQt::Key_Control
"Up"
toQt::Key_Up
"a"
toQt::Key_A
"5"
toQt::Key_5
As you see the above includes not just alpha numeric keys but modifiers and special keys. I'm not attached to the Qt keycode enum, but it seems that Qt has this parsing functionality in QKeySequence
's fromString
static function (see this direct link):
QKeySequence fromString(const QString & str, SequenceFormat format);
You might as why I need this conversion. Well, I have a data file generated by GhostMouse. It's a log of what I type. Here's an example of me typing " It "
:
{SPACE down}
{Delay 0.08}
{SPACE up}
{Delay 2.25}
{SHIFT down}
{Delay 0.11}
{i down}
{Delay 0.02}
{SHIFT up}
{Delay 0.03}
{i up}
{Delay 0.05}
{t down}
{Delay 0.08}
{t up}
{Delay 0.05}
{SPACE down}
{Delay 0.12}
{SPACE up}
So I need a way to convert the string "SPACE" and all the other strings representing keys in this data file to a unique int
.