focused item. If \a delay is larger than 0, the test will wait for
\a delay milliseconds.
+ The event will be sent to the TestCase window or, in case of multiple windows,
+ to the current active window. See \l QGuiApplication::focusWindow() for more details.
+
\b{Note:} At some point you should release the key using keyRelease().
\sa keyRelease(), keyClick()
focused item. If \a delay is larger than 0, the test will wait for
\a delay milliseconds.
+ The event will be sent to the TestCase window or, in case of multiple windows,
+ to the current active window. See \l QGuiApplication::focusWindow() for more details.
+
\sa keyPress(), keyClick()
*/
function keyRelease(key, modifiers, delay) {
focused item. If \a delay is larger than 0, the test will wait for
\a delay milliseconds.
+ The event will be sent to the TestCase window or, in case of multiple windows,
+ to the current active window. See \l QGuiApplication::focusWindow() for more details.
+
\sa keyPress(), keyRelease()
*/
function keyClick(key, modifiers, delay) {
bool QuickTestEvent::keyPress(int key, int modifiers, int delay)
{
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyPress(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay);
bool QuickTestEvent::keyRelease(int key, int modifiers, int delay)
{
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyRelease(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay);
bool QuickTestEvent::keyClick(int key, int modifiers, int delay)
{
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyClick(window, Qt::Key(key), Qt::KeyboardModifiers(modifiers), delay);
bool QuickTestEvent::keyPressChar(const QString &character, int modifiers, int delay)
{
QTEST_ASSERT(character.length() == 1);
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyPress(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay);
bool QuickTestEvent::keyReleaseChar(const QString &character, int modifiers, int delay)
{
QTEST_ASSERT(character.length() == 1);
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyRelease(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay);
bool QuickTestEvent::keyClickChar(const QString &character, int modifiers, int delay)
{
QTEST_ASSERT(character.length() == 1);
- QWindow *window = eventWindow();
+ QWindow *window = activeWindow();
if (!window)
return false;
QTest::keyClick(window, character[0].toLatin1(), Qt::KeyboardModifiers(modifiers), delay);
return 0;
}
+QWindow *QuickTestEvent::activeWindow()
+{
+ if (QWindow *window = QGuiApplication::focusWindow())
+ return window;
+ return eventWindow();
+}
+
QT_END_NAMESPACE