QTimer wait interval time before executing code first time
-
Yeah, but there is other problem too, I want to execute it on for example F3 pressed. Do I need another loop for this?
if(config->enabled){ if(config->f_flask1State()){ clickButton(config->flask1Key); } } if(GetAsyncKeyState(config->enablerBtn)){ releaseButton(config->enablerBtn); config->enabled = true; } if(GetAsyncKeyState(config->disablerBtn)){ releaseButton(config->disablerBtn); config->enabled = false; }
-
Don't use WinAPI but Qt: QWidget::keyPressEvent() e.g. here: https://forum.qt.io/topic/114207/keypressevent
-
@Christian-Ehrlicher said in QTimer wait interval time before executing code first time:
QWidget::keyPressEvent()
In this Loop to handle keys instead of
GetAsyncKeyState
? But why? -
@BD9a said in QTimer wait interval time before executing code first time:
But why?
Because you will block the ui otherwise.
-
@Christian-Ehrlicher I dont know what u want to do, but my UI is fine with this winapi. Im using Qt Quick if it does matter.
-
@BD9a said in QTimer wait interval time before executing code first time:
I have QTimer started with 3000msec interval. Is there a way to make it execute code and then wait this interval instead of wait interval and execute?
Perhaps using standard C/C++ sleep(0 instead QTimer would work in your case ?
-
@AnneRanch Sleep will freeze my gui. I will probably use another loop to control it.
Or maybe there's another solution. -
@BD9a said in QTimer wait interval time before executing code first time:
Or maybe there's another solution.
Yes, use the functions Qt provides to you as I explained above...
-
@Christian-Ehrlicher what? with sleep only my gui can be frozen. My gui without sleep works fine...
-
@BD9a
Hi
No Mr Ehrlicher just want you to use the normal Qt keyboard handling routines to detect the
F3 key so we dont have to loop around GetAsyncKeyState to see if key was pressed.
and when event comes with, call the timers slots code and then start timer. -
@mrjj That sounds better, but im doing sth wrong definetly.
I'm using
Qt Quick
, to Class where those loops are I just included#include <QEvent> #include <QKeyEvent>
protected: bool eventFilter(QObject* obj, QEvent* event);
bool Loop::eventFilter(QObject *obj, QEvent *event) { if (event->type()==QEvent::KeyPress) { QKeyEvent* key = static_cast<QKeyEvent*>(event); if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) ) { qDebug() << "enter"; } else { return QObject::eventFilter(obj, event); } return true; } else { return QObject::eventFilter(obj, event); } return false; }
And now this eventFilter should be in loop? cuz it's not working in current state.
-
@BD9a
Hi
So loop class is the handler of the filter
and you set this filter on the object where you will press F3 on ?
or on Application ?
https://doc.qt.io/qt-5/qobject.html#installEventFilter -
@BD9a Since, you Using QML, have you considered using Shortcut-QML-Type
https://doc.qt.io/qt-5/qml-qtquick-shortcut.html
? -
@BD9a No Qt way, you'll have to look into your OS specific apis and/or install very low level Keyboard hooks,
https://docs.microsoft.com/de-de/windows/win32/api/winuser/nf-winuser-setwindowshookexa?redirectedfrom=MSDN