Add delay feature to autotype (#77)

* Implement {DELAY=X} in autotype
This commit is contained in:
Jonathan White 2016-11-04 18:05:47 -04:00 committed by GitHub
parent ac108cd708
commit 753d1d50d0
2 changed files with 22 additions and 1 deletions

View File

@ -37,6 +37,7 @@ AutoType* AutoType::m_instance = nullptr;
AutoType::AutoType(QObject* parent, bool test)
: QObject(parent)
, m_inAutoType(false)
, m_autoTypeDelay(0)
, m_currentGlobalKey(static_cast<Qt::Key>(0))
, m_currentGlobalModifiers(0)
, m_pluginLoader(new QPluginLoader(this))
@ -303,6 +304,8 @@ bool AutoType::parseActions(const QString& sequence, const Entry* entry, QList<A
{
QString tmpl;
bool inTmpl = false;
m_autoTypeDelay = 0;
for (const QChar& ch : sequence) {
// TODO: implement support for {{}, {}} and {DELAY=X}
@ -332,7 +335,17 @@ bool AutoType::parseActions(const QString& sequence, const Entry* entry, QList<A
actions.append(new AutoTypeChar(ch));
}
}
if (m_autoTypeDelay > 0) {
QList<AutoTypeAction*>::iterator i;
i = actions.begin();
while (i != actions.end()) {
++i;
if (i != actions.end()) {
i = actions.insert(i, new AutoTypeDelay(m_autoTypeDelay));
++i;
}
}
}
return true;
}
@ -342,6 +355,13 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
int num = -1;
QList<AutoTypeAction*> list;
QRegExp delayRegEx("delay=(\\d+)", Qt::CaseSensitive, QRegExp::RegExp2);
if (delayRegEx.exactMatch(tmplName)) {
num = delayRegEx.cap(1).toInt();
m_autoTypeDelay = std::max(0, std::min(num, 10000));
return list;
}
QRegExp repeatRegEx("(.+) (\\d+)", Qt::CaseSensitive, QRegExp::RegExp2);
if (repeatRegEx.exactMatch(tmplName)) {
tmplName = repeatRegEx.cap(1);

View File

@ -69,6 +69,7 @@ private:
bool windowMatches(const QString& windowTitle, const QString& windowPattern);
bool m_inAutoType;
int m_autoTypeDelay;
Qt::Key m_currentGlobalKey;
Qt::KeyboardModifiers m_currentGlobalModifiers;
QPluginLoader* m_pluginLoader;