Perform action at timed intervals when holding key down
-
I'm creating a media player using Qt and libvlc (VLC-Qt) and I want to add fast-forward and rewind functionality when a key is held down (such as left/right arrow keys or media forward/backward keys). I'm thinking that I should set the position of the media to increase/decrease by some fixed amount at a timed interval when a key is held down, but perform some other action when it's just pressed (like go to next media in library/playlist). Has anyone done something like this before, or does anyone have any ideas? Perhaps Qt provides a solution for this type of thing already? Any help would be greatly appreciated.
-
Hi,
You can use a QTimer that will timeout after a certain amount of time and trigger the slot that will do the move the way you want it. You can start it by reimplementing keyPressEvent and stop it from keyReleaseEvent.
Hope it helps.
-
@SGaist said:
Hi,
You can use a QTimer that will timeout after a certain amount of time and trigger the slot that will do the move the way you want it. You can start it by reimplementing keyPressEvent and stop it from keyReleaseEvent.
Hope it helps.
Ahh, I didn't really think about stopping the timer on the keyReleaseEvent. Thank you very much. I guess I could just see how much time has passed between the press and the release to determine if it was just pressed or if it was held down. Thank you for your response. I think I should be able to accomplish this.
-
That's what the timer is for. If you press the key long enough then it will fire but if you release it quicker that the timeout, the timer will be cancelled, no need to measure the time between both events.